public SensorBase(int id, string sensorname, System.Net.IPEndPoint endpoint ) { this.ComType = COMTYPE.TCP; this.SensorName = sensorname; this.endpoint = endpoint; new System.Threading.Thread(TCPConnectTask).Start(); ID = id; OneMinTmr.Interval = 1000 * 60; OneMinTmr.Elapsed += new System.Timers.ElapsedEventHandler(OneMinTmr_Elapsed); OneMinTmr.Start(); }
public SensorBase(int id, string sensorname, string ComPort, int baud) { this.ComPort = ComPort; this.baud = baud; this.SensorName = sensorname; ComType = COMTYPE.COM; ComConnect(); ID = id; OneMinTmr.Interval = 1000 * 60; OneMinTmr.Elapsed += new System.Timers.ElapsedEventHandler(OneMinTmr_Elapsed); OneMinTmr.Start(); }
private void CreateAndSendCommand(Command com,Udp udp,COMTYPE comtype) { if (udp == null) { return; } if (bCommandBusy) { return; } ushort addr; if (!ushort.TryParse(txtAddr.Text,out addr)) { addr = 0; } switch (comtype) { case COMTYPE.CONFIG_RS: { int timeoutRazdel,periodCycle,timeoutWait; if (!int.TryParse(txtTimeoutRazdel.Text,out timeoutRazdel)) { timeoutRazdel = 0; } if (!int.TryParse(txtPeriodCycle.Text,out periodCycle)) { periodCycle = 0; } if (!int.TryParse(txtTimeoutWait.Text,out timeoutWait)) { timeoutWait = 0; } com = new Command(addr,9,SET_OR_GET.OTHER,0,CommandType.TYPICAL); //for (int i = 0; i < com_out.data.Length; i++) com_out.data[i] = (byte)i; com.data[0] |= (byte)cmbSpeedUart.SelectedIndex; com.data[1] |= (byte)(cmbParity.SelectedIndex + 1); if (radMaster.Checked) { com.data[1] |= (1 << 3); } com.data[1] |= (byte)((cmbStopBits.SelectedIndex) << 4); if (radRS485.Checked) { com.data[1] |= (1 << 6); } if (radReadWrite.Checked) { com.data[1] |= (1 << 7); } com.data[3] = (byte)(timeoutRazdel / 100); com.data[4] = (byte)(((timeoutRazdel / 100) >> 8) & 0xFF); com.data[5] = (byte)(periodCycle); com.data[6] = (byte)((periodCycle >> 8) & 0xFF); com.data[7] = (byte)(timeoutWait / 100); com.data[8] = (byte)(((timeoutWait / 100) >> 8) & 0xFF); break; } case COMTYPE.FREE: { byte[] buf; string str = txtTVPOut.Text; try { buf = str.Split(',').Select(n => Convert.ToByte(n,16)).ToArray(); com = new Command(addr,(ushort)buf.Length,SET_OR_GET.OTHER,0,CommandType.TYPICAL); Array.Copy(buf,com.data,buf.Length); } catch { com = new Command(addr,0,SET_OR_GET.OTHER,0,CommandType.TYPICAL); } break; } case COMTYPE.SIGNAL: { } break; } ShowBuf(com.GetCommandByteBuf(),BUF_TO_SHOW.TX); bCommandBusy = true; udp.SendCommand(com); while (bCommandBusy) { this.Cursor = Cursors.AppStarting; Application.DoEvents(); } this.Cursor = Cursors.Default; }