I wrote a script in C# on my PC that opens up a USB port and talks to a weighing machine. Unfortunately, when I tried to do the exact same thing using mono on my raspberry pi, my readChar function times out.
The weighing machine uses a protocol where if you send an ENQ character to it, it sends you a sequence of 20 characters which you can interpret.
I'm able to open the port and set its settings, and then I write ENQ to the port - no errors so far. Immediately after, I try to readChar and hit a timeout error.
Has anyone seen anything like this before? Is it possible that my write isn't working at all?
Code:
private static SerialPort WeightPort;
WeightPort = new SerialPort("/dev/ttyUSB0", 9600, Parity.None, 8, StopBits.One);
WeightPort.WriteTimeout = 2000;
WeightPort.ReadTimeout = 2000;
WeightPort.Open();
WeightPort.Write(ENQ); //ENQ is a string that stores the ENQ ascii character
t = WeightPort.ReadChar(); //times out
I'm using C# because I'm using a library that requires C#. But I've tested this through Python on the Pi as well and it still refuses to write, but can read.
– Rohil Verma Jul 04 '17 at 18:47