Hi all.
I have a strange problem with the USB-serial module (USB serial 1.3 on 4.2 framework) and strings transmission betwen the serial and a PC. :wall:
I already read everything I found in the documentations AND in this forum, but nothing suggested me a solution.
1- When i ONLY send data (strings) FROM the USB-SERIAL to the PC, everything SEEMS to be ok (apparently no data is corrupted or missing in my samples)
2- When i ONLY send data (strings) FROM the PC to the USB-SERIAL, everything SEEMS to be ok (apparently no data is corrupted or missing in my samples)
3- When i try sending and receiving data simultanously and bidirectionaly from/to the PC and the USB-SERIAL module (e.g. using a timer on both sides or buttons that raise events and call write/writeline) the received data on both sides is randomly broken (missing bytes, or senseless binary content instead of the expected characters).
About 10% of the data sent seems to be broken
I tried all these (also mixing various techniques hoping it could work):
A- using usbSerial.SerialLine.LineReceived
B- using usbSerial.SerialLine.DataReceived (manually handling ‘\n’ characters)
C- using usbSerial.SerialLine.Write
D- using usbSerial.SerialLine.WriteLine
E- adding locks (lock(myLock){…}) during reads and writes to guarantee that they are not concurrent (at least inside my code)
F- using a different USB-serial module (I have 2 modules, they have the same strange behaviour)
G- playing with ALL the configuration parameters (like baud rate, parity, flow control, and so on)… so since nothing changes, i think they are not meaningfull for my problem. Obviously the settings of the module always matches the settings of the serial on the PC.
Could please anyone suggest me a way to solve this problem ?
What is the correct way to implement bidirectional concurrent communication using the USB-serial module ?
Some code samples ?
What hardware are you using? I’m having serial communication issues on the G400/Raptor when it talks to the GSM Module over serial. It’s like you describe here… missing bits every now and then… using NETMF 4.2, GHI 2014 SDK and latest firmware/bootloader
In the zip there is a Visual Studio 2010 solution with 2 programs.
NJC_WindowsForms_USB_Serial_Test → The programs that runs on the PC.
Using a timer, it sends messages prefixed with “<PC_” to the serial port, and receive messages from the gadgeteer mobo.
NJC_Gadgeteer_USB_Serial_Test → The program that runs on the gadgeteer mobo.
Using a timer, it sends to the PC messages prefixed with “<GADGETEER_”.
When it receive a message from the PC, it sends it back (infact in the “received” box of the screenshot you can find both “<PC_” and “<GADGETEER_” messages)
As you can see from the attached screenshot, some messages from the PC (the ones that starts with “<PC” and red arrows) are broken.
Those are the messages received by the gadgeteer mobo from the PC, and sent back to the PC
Hi,
at the Moment I do not have the time to test your code, but perhaps a look on these threads helps. It concerns the rs232 module, but the problems should be the same.
Thankyou for the suggestion.
I tried the modifications you suggested, but even if the errors are a bit less frequent, they still happen too much often (5% of messages is corrupted)
Any other hints ?
This would not solve the fact that the Spider receive broken data, this would (maybe) only solve the fact that the PC receive broken data from the Spider.
How do I solve the fact that the Spider receive broken data ?
I followed you suggestions, and I managed to get a stable bidirectonal communication.
Unfortunately I can obtain such stability only at a trasmission rate of about 100 chars/second, and this is unacceptable for the kind of application I’m developing.
If I increase the data exchange rate some messages are lost or arrives broken.
So by now my problem is a duplicity of instability and/or speed.
Maybe I’m approaching the problem in the wrong way, so let’s rollback to the root.
First of all: what is the most reliable way to make robust bidirectional simultaneous serial communication between Gadgeteer and a PC ?
Faster transmission would require use of RTS/CTS. I did not catch it before, but there are 2 jumpers on the module next to the IC. Bridging J1 connects RTS on the IC and bridging J2 connects CTS on the IC.
Could you place a jumper for both of these and retry with handshaking enabled?