0

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 guess that we will need some more details about your program. We cannot figure out what's wrong if you don't show anything... – YCN- Jul 03 '17 at 07:57
  • of course, my apologies, updated with code – Rohil Verma Jul 03 '17 at 16:04
  • Firstly I'm wondering why would you use C# on a linux system ? That can be part of the problem. But then there's also another thing not clear do you use the GPIO pins for serial communication or did you plug a USB to serial wire ? – YCN- Jul 04 '17 at 07:35
  • I'm using a USB to RS232 connector - I've isolated the problem to the Write function not working correctly since I've got the read functions working correctly.

    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

1 Answers1

0

The issue turned out to be as simple as updating my firmware:

sudo rpi-update

did the trick.

  • Please accept your own answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year. – Ingo Jan 07 '20 at 22:07
  • Any idea why this solved your issue? rpi-update is very discouraged by the rpi folks unless specifically directed by an rpi engineer. – Jim Yarbro Sep 17 '20 at 14:20