I work with Hydra and use rs 232 for transfer data from host to Hydra.
i want to set ReadTimeout for 60000 and have some problems.
here is the code:
rS232.serialPort.ReadTimeout = 60000; //waiting 1 minutes before timeout
in that case i get an error because the port is already open.
But when i try to set this timeout before the rS232.Initialize(); i also get an exception:
“An unhandled exception of type ‘System.NullReferenceException’ occurred in…”
what can i do?
Do you have opened the port somewhere else?
Or do you have solved this one already (I saw your other post).
and please use code tags for code (the 101010 Button above the edit window)
Thanks on the “101010” tip…
No. i dont open it before.
the problem is that “Initialize” method creates and opens the port, and i need to sparate those two operations…
i tried to solve my problem in several ways:
- i tried to colse this port after Initialize and reopen it after - but this property is get only…
2 i tried to create Serial manually:
rS232.serialPort = new Serial(Socket.GetSocket(7,false,null,""),38400,Serial.SerialParity.None,Serial.SerialStopBits.One,8,Serial.HardwareFlowControl.NotRequired,null );
but then i got an exception when i tried to call to Initialize. (exception - this socket is already i use…)
as you saw i want to set the timeout because i want to use timeout Exception.
What you’re seeing there is the Gadgeteer socket reservation because you have the rs232 module in the design. If you use your code above, and don’t include the module on the designer, you should be ok.
You might want to dig into the Gadgeteer code on codeplex to see how the constructor works and if there’s a method to set the read timeout natively using the initialize method.