मेरे पास एक ऐसा एप्लिकेशन है जो rs232 के माध्यम से विभिन्न हार्डवेयर पढ़ता है। यह परीक्षण किया गया है और यह पूरी तरह से काम कर रहा था। अंतिम आवेदन के लिए मुझे कुछ हंडर मीटर लम्बी केबल पेश करने की आवश्यकता थी जिसका मतलब है कि मेरे पास rs485 कन्वर्टर्स हैं।लंबे केबल समय पर सीरियल संचार टाइमआउट
जब मैं हार्डवेयर पढ़ने के लिए अपना आवेदन चलाता हूं तो मुझे System.IO.Ports.SerialStream.Read के लिए एक टाइम आउट त्रुटि मिलती है। मैंने समय-समय पर 20sec में वृद्धि की है दुर्भाग्य से इस समस्या को हल नहीं किया
मैंने हार्डवेयर को पढ़ने के लिए विभिन्न अनुप्रयोगों का प्रयास किया है और उन्होंने 1sec पढ़ने की आवृत्ति के साथ भी काम किया है।
संचार मॉडबस प्रोटोकॉल का उपयोग कर रहा है, जो वर्तमान चरण में है, मुझे लगता है कि मैं कुछ भी प्राप्त करने के लिए मंच पर नहीं पहुंचता हूं।
मेरे कोड इस तरह दिखता है: पहले सीरियल पोर्ट खोलने और प्रारंभ:
//get the right modbus data structure element
ModBus MB = (ModBus)s[0].sensorData;
//set up the serial port regarding the data structure's data
SerialPort sp = new SerialPort();
sp.PortName = MB.portName;
sp.BaudRate = Convert.ToInt32(MB.baudRate);
sp.DataBits = MB.dataBits;
sp.Parity = MB.parity;
sp.StopBits = MB.stopBits;
//Set time outs 20 sec for now
sp.ReadTimeout = 20000;
sp.WriteTimeout = 20000;
// एक सूची है जो पाठक portList.Add (सपा) द्वारा पहुँचा जा सकता करने के लिए बंदरगाह को जोड़ने; sp.Open();
पढ़ें हार्डवेयर:
//get the right port for com
SerialPort sp = getRightPort();
ModBus MB = getRightModBusStructureelement();
try
{
//Clear in/out buffers:
sp.DiscardOutBuffer();
sp.DiscardInBuffer();
//create modbus read message
byte[] message = createReadModBusMessage();
try
{
sp.Write(message, 0, message.Length);
// FM.writeErrorLog output included for easier debug
FM.writeErrorLog(DateTime.Now + ": ModBus Message Sent");
FM.writeErrorLog(DateTime.Now + ": Read TimeOut = " + sp.ReadTimeout + " Write TimeOut = " + sp.WriteTimeout);
int offset = 0, bytesRead;
int bytesExpected = response.Length;
FM.writeErrorLog(DateTime.Now + ": start read");
while (bytesExpected > 0 && (bytesRead = sp.Read(response, offset, bytesExpected)) > 0)
{
FM.writeErrorLog(DateTime.Now + ": read - " + offset);
offset += bytesRead;
bytesExpected -= bytesRead;
}
}
catch (Exception err)
{
Console.WriteLine("ERROR Modbus Message to serial port ModBus: " + err);
FM.writeErrorLog(DateTime.Now + " - " + "ERROR Modbus Message to serial port ModBus: " + err);
}
}
आवेदन की कोशिश के बाद मैं ErroLog.txt से निम्नलिखित उत्पादन मिल गया:
14/01/2016 17:18:17: ModBus Message Sent
14/01/2016 17:18:17: Read TimeOut = 20000 Write TimeOut = 20000
14/01/2016 17:18:18: start read
14/01/2016 17:18:38 - ERROR Modbus Message to serial port ModBus: System.TimeoutException: The operation has timed out.
at System.IO.Ports.SerialStream.Read(Byte[] array, Int32 offset, Int32 count, Int32 timeout)
at System.IO.Ports.SerialStream.Read(Byte[] array, Int32 offset, Int32 count)
at System.IO.Ports.SerialPort.Read(Byte[] buffer, Int32 offset, Int32 count)
at ProbReader.SensorReader.modbusReading(List`1 mm, Int32 spCounter)
14/01/2016 17:18:38: 0
14/01/2016 17:18:38: 0
मैं टाइमआउट वृद्धि हुई है सिर्फ मामले में, लेकिन एक ही त्रुटि 60sec रहे हैं:
15/01/2016 11:11:51: ModBus Message Sent
15/01/2016 11:11:51: Read TimeOut = 60000 Write TimeOut = 60000
15/01/2016 11:11:51: start read
15/01/2016 11:12:51 - ERROR Modbus Message to serial port ModBus: System.TimeoutException: The operation has timed out.
at System.IO.Ports.SerialStream.Read(Byte[] array, Int32 offset, Int32 count, Int32 timeout)
at System.IO.Ports.SerialStream.Read(Byte[] array, Int32 offset, Int32 count)
at System.IO.Ports.SerialPort.Read(Byte[] buffer, Int32 offset, Int32 count)
at ProbReader.SensorReader.modbusReading(List`1 mm, Int32 spCounter)
15/01/2016 11:12:51: 0
15/01/2016 11:12:51: 0
मैंने धारावाहिक बंदरगाह पढ़ने के कुछ अलग तरीकों की कोशिश की है, मुझे लगता है कि टी वह वर्तमान विधि सबसे अच्छा दिखता है जो मेरे पढ़ने कोड में थोड़ी देर लूप है।
मैंने अपने शेष कोड को पहले के समय में शामिल नहीं किया था और मुझे लगता है कि यह अप्रासंगिक है।
मुझे आरटीएस/सीटीएस जैसे हार्डवेयर प्रवाह नियंत्रण का कोई सबूत नहीं दिख रहा है। सॉफ़्टवेयर फ्लो-कंट्रोल से पहले भी मेरी पहली पसंद होगी जो मुझे संदेह है कि आपके परिस्थिति – MickyD
में अविश्वसनीय है, इसके अलावा, आपका उपरोक्त कोड वास्तव में _ मूल्यों को दिखाता है जो आप _parity के लिए उपयोग कर रहे हैं; डेटा बिट्स; बॉड; बिट्स रोको; _ और बहुत आगे। किसी भी मौके पर आप 'एमबी' में मूल्यों को डंप कर सकते हैं? – MickyD
क्या आपने COM से आईपी कनवर्टर का उपयोग करने के बारे में सोचा है? फिर आप एक टीसीपी-सॉकेट के माध्यम से अपना डेटा प्राप्त कर सकते हैं और आप एक लंबी दूरी को संभालने में सक्षम हो सकते हैं। – etalon11