Extended Full Duplex serial w/ multiple instances (array of objects)
Chicago Mike
Posts: 88
I'm trying to run two serial ports independently, both however using extended_full duplex serial. So I'm trying to have multiple instances of this object.... After reviewing the prop manual, I noticed that you can call build an array of the same object, so I gave that a shot (As shown below). (Please ignore the "//" below. I can't seem to display array references in this forum text editor without it, they are not there in real code).
Now, my understanding of the above code would be that I would be running two instances of the Extended_FDserial object (Yes, DAT sections are shared, but the variables, including the rxbuffer are separate), which would give me two exclusive and different receive buffers. This does not seem to be the case. If I send in a string such as "hello" on the first serial line, and run the above code input1 will be "h", and input 2 will be "e". My goal is to have input1=="h" and input2==-1 (Because there was no input on the second port, to the second instance of the object). Perhaps my understanding of an array of objects is wrong. I also tried just duplicating the object reference such as below
This did not work so well, when I attempted to do a serial2.rxcheck, it would consistently reboot the prop.
I'm sure someone has done this before? Any tips? To add to this I would also like to use the fullduplex object for RX and TX on the same pin. After I figured out the above, I wanted to to tie the RX,TX together and the DERE lines together. (I'm talking to 75176 RS485 transceiver). I want to keep the DERE line low normally to receive on the data line. Then when I needed to transmit, I would set the DERE line high and transmit on the dataline. Has anyone used the Extended_FullDuplex object this way?
Any help would be great! Thanks again!
Post Edited (Chicago Mike) : 1/26/2008 3:27:10 PM GMT
OBJ serial[noparse][[/noparse]//1] : "Extended_FDserial" PUB Main | input1, input2 serial[noparse][[/noparse]//0].start(1,2,%0000,9600) serial[noparse][[/noparse]//1].start(3,4,%0000,9600) input1:=serial[noparse][[/noparse]//0].rxcheck input2:=serial[noparse][[/noparse]//1].rxcheck
Now, my understanding of the above code would be that I would be running two instances of the Extended_FDserial object (Yes, DAT sections are shared, but the variables, including the rxbuffer are separate), which would give me two exclusive and different receive buffers. This does not seem to be the case. If I send in a string such as "hello" on the first serial line, and run the above code input1 will be "h", and input 2 will be "e". My goal is to have input1=="h" and input2==-1 (Because there was no input on the second port, to the second instance of the object). Perhaps my understanding of an array of objects is wrong. I also tried just duplicating the object reference such as below
OBJ serial1 : "Extended_FDserial" serial2 : "Extended_FDserial"
This did not work so well, when I attempted to do a serial2.rxcheck, it would consistently reboot the prop.
I'm sure someone has done this before? Any tips? To add to this I would also like to use the fullduplex object for RX and TX on the same pin. After I figured out the above, I wanted to to tie the RX,TX together and the DERE lines together. (I'm talking to 75176 RS485 transceiver). I want to keep the DERE line low normally to receive on the data line. Then when I needed to transmit, I would set the DERE line high and transmit on the dataline. Has anyone used the Extended_FullDuplex object this way?
Any help would be great! Thanks again!
Post Edited (Chicago Mike) : 1/26/2008 3:27:10 PM GMT
Comments
(a) Blanks will do rather than //
(b) In your first example you have NOT created 2 instances; that would need:
(c) Is this the complete code? If you use RCFAST rather than 80 MHz it might not work.
There should be no propeller reset!
And it should work in general...
Edit:
Just made some tests... It seems the access to an object is clipped to the last one. THis explanes the "e" (= second letter) Mike has seen...
Post Edited (deSilva) : 1/26/2008 4:10:28 PM GMT
Now at this point I have nothing wired to pin b485txrx, so serial[noparse][[/noparse] 2 ], has no input, hence I should get a return of -1. My results of this without ANY input to either serial device is rfinput == -1 (as expected), however lineinput == 0 (which, I think should be -1 as there is no input). Any idea why?
I went back to the multiple instance method as listed above instead of calling the same object twice and assigning it to a different name, as I still was having the reboot problem when I would attempt to rx.check from the second device.
Thanks!
(1) You define serial[noparse][[/noparse] 2]: ....
(2) You use serial[noparse][[/noparse] 0] and serial[noparse][[/noparse] 1]
You did it vice versa...