public static void Intconfig() { config_Path = FunComm.GetStartupPath() + "数据文件\\"; config_file_name = "config.txt"; if (!Directory.Exists(config_Path)) //不存在文件夹则创建 { Directory.CreateDirectory(config_Path); FileStream configfile = new FileStream(config_Path + config_file_name, FileMode.Create); configfile.Close(); //初始化config信息 string config_str = "串口号" + "," + "波特率" + "," + "数据位" + "," + "校验位" + "," + "停止位" + "," + "窗口号" + "," + "文件路径" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str); string config_str1 = "COM1" + "," + "B9600" + "," + "BIT_8" + "," + "None" + "," + "Stop_1" + "," + "0" + "," + "" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str1); string config_str2 = "COM2" + "," + "B9600" + "," + "BIT_8" + "," + "None" + "," + "Stop_1" + "," + "0" + "," + "" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str2); string config_str3 = "COM3" + "," + "B9600" + "," + "BIT_8" + "," + "None" + "," + "Stop_1" + "," + "0" + "," + "" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str3); string config_str4 = "COM4" + "," + "B9600" + "," + "BIT_8" + "," + "None" + "," + "Stop_1" + "," + "0" + "," + "" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str4); string config_str5 = "COM5" + "," + "B9600" + "," + "BIT_8" + "," + "None" + "," + "Stop_1" + "," + "0" + "," + "" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str5); string config_str6 = "COM6" + "," + "B9600" + "," + "BIT_8" + "," + "None" + "," + "Stop_1" + "," + "0" + "," + "" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str6); string config_str7 = "COM7" + "," + "B9600" + "," + "BIT_8" + "," + "None" + "," + "Stop_1" + "," + "0" + "," + "" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str7); string config_str8 = "COM8" + "," + "B9600" + "," + "BIT_8" + "," + "None" + "," + "Stop_1" + "," + "0" + "," + "" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str8); string config_str9 = "10.126.1.192" + "," + "9000" + "," + "qdsb422" + "," + "qdsb422" + "," + "127.0.0.1" + "," + "0x84" + "," + "0x64" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str9); } }
public static void DisConnect(string user, string password, string terminalstr)//断开连接 { try { FunComm.TCP = false; FunComm.Logoff(user, password, terminalstr); FunComm.sck.Disconnect(true); FunComm.sck.Close(); } catch { FunComm.TCP = false; FunComm.sck.Disconnect(true); FunComm.sck.Close(); } }
public static void Send_apply(string terminalstr)//申请命令 { DateTime StartTime = new DateTime(1970, 1, 1, 00, 00, 00); byte[] info = new byte[21]; info[0] = 0x11;//实时数据 info[1] = 0x00; info[2] = 0xAA; // info[3] = 0x84;//卫星型号 info[3] = FunComm.myTCP.mark; UInt32 Seconds = (UInt32)(DateTime.Now - StartTime).TotalSeconds; info[4] = (byte)((Seconds >> 24) & (0x000000FF)); info[5] = (byte)((Seconds >> 16) & (0x000000FF)); info[6] = (byte)((Seconds >> 8) & (0x000000FF)); info[7] = (byte)(Seconds & 0x000000FF); string[] bb = new string[10]; bb = terminalstr.Split('.'); info[8] = byte.Parse(bb[0]); info[9] = byte.Parse(bb[1]); info[10] = byte.Parse(bb[2]); info[11] = byte.Parse(bb[3]); // info[12] = 0x61;//申请数据类型 11...61 info[12] = FunComm.myTCP.equ; info[13] = 0x00; info[14] = 0x13;//地面设备 // info[15] = 0x84;//卫星代号 info[15] = FunComm.myTCP.mark; info[16] = 0x00;//原码或者物理量 info[17] = (byte)((Seconds >> 24) & (0x000000FF)); info[18] = (byte)((Seconds >> 16) & (0x000000FF)); info[19] = (byte)((Seconds >> 8) & (0x000000FF)); info[20] = (byte)(Seconds & 0x000000FF); FunComm.DataSend(info); }
public static void Send_sta(byte [] data, string terminalstr)//发送命令执行状态 { DateTime StartTime = new DateTime(1970, 1, 1, 00, 00, 00); byte[] info = new byte[21]; // info[0] = 0x61;//数据源或属性定义字段 11.....61 info[0] = FunComm.myTCP.equ; info[1] = 0x00; info[2] = 0x55; // info[3] = 0x84;//卫星型号 info[3] = FunComm.myTCP.mark; UInt32 Seconds = (UInt32)(DateTime.Now - StartTime).TotalSeconds; info[4] = (byte)((Seconds >> 24) & (0x000000FF)); info[5] = (byte)((Seconds >> 16) & (0x000000FF)); info[6] = (byte)((Seconds >> 8) & (0x000000FF)); info[7] = (byte)(Seconds & 0x000000FF); string[] bb = new string[10]; bb = terminalstr.Split('.'); info[8] = byte.Parse(bb[0]); info[9] = byte.Parse(bb[1]); info[10] = byte.Parse(bb[2]); info[11] = byte.Parse(bb[3]); info[12] = data[0]; info[13] = data[1]; info[14] = (byte)((serial_num >> 24) & (0x000000FF)); info[15] = (byte)((serial_num >> 16) & (0x000000FF)); info[16] = (byte)((serial_num >> 8) & (0x000000FF)); info[17] = (byte)(serial_num & 0x000000FF); info[18] = 0x01; info[19] = 0x00; info[20] = data[2]; FunComm.DataSend(info); }
//读取初始化信息 public static void IntCOM() { config_Path = FunComm.GetStartupPath() + "数据文件\\"; config_file_name = "config.txt"; if (Directory.Exists(config_Path)) //存在文件夹则初始化串口 { string[] config = File.ReadAllLines(FunComm.config_Path + FunComm.config_file_name); for (int i = 1; i < config.Length - 1; i++) { string[] config_i = config[i].Split(','); if (config_i.Length > 0)//有内容 { Readconfig(config_i, i); } //if (config_i.Length ==1)//有内容 //{ // Readcom(config_i,i); //} } string[] config_tcp = config[config.Length - 1].Split(','); Readtcp(config_tcp, config.Length - 1); } }
public static string SetPort_old(int num)//设置NUM行串口 { ///////配置/// int port = FunComm.myCOMMDATA[num].Port; int mode = FunComm.myCOMMDATA[num].ByteSize | FunComm.myCOMMDATA[num].Parity | FunComm.myCOMMDATA[num].StopBits; // int hw = FunComm.myCOMMDATA[COMport].Hw ? 3 : 0; /* bit0 and bit1 */ // int sw = FunComm.myCOMMDATA[COMport].Sw ? 12 : 0; /* bit2 and bit3 */ int ret; //DWORD tout; string str = null; //打开某个串口 if ((ret = FunComm.sio_open(port)) != FunComm.SIO_OK) { str = FunComm.MxShowError(ret); // MessageBox.Show(str, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return(str); } //设置串口参数 if ((ret = FunComm.sio_ioctl(port, FunComm.myCOMMDATA[num].BaudRate, mode)) != FunComm.SIO_OK) { //设置 str = FunComm.MxShowError(ret); // MessageBox.Show(str, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return(str); } if (str == null) { FunComm.myCOMMDATA[num].GbOpen = true;//串口请求成功 } else { FunComm.myCOMMDATA[num].GbOpen = false;//串口开启失败或者被关闭 } return(str); /////////设置 Port /// //int port = FunComm.myCOMMDATA[COMport].Port; //int mode = FunComm.myCOMMDATA[COMport].ByteSize | FunComm.myCOMMDATA[COMport].Parity | FunComm.myCOMMDATA[COMport].StopBits; //int hw = FunComm.myCOMMDATA[COMport].Hw ? 3 : 0; /* bit0 and bit1 */ //int sw = FunComm.myCOMMDATA[COMport].Sw ? 12 : 0; /* bit2 and bit3 */ //int ret; ////DWORD tout; //string str; ////打开某个串口 //if ((ret = FunComm.sio_open(port)) != FunComm.SIO_OK) //{ // str = FunComm.MxShowError(ret); // MessageBox.Show(str, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} ////设置串口参数 //if ((ret = FunComm.sio_ioctl(port, FunComm.myCOMMDATA[COMport].BaudRate, mode)) != FunComm.SIO_OK) //{ //设置 // str = FunComm.MxShowError(ret); // MessageBox.Show(str, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} //if ((ret = FunComm.sio_flowctrl(port, hw | sw)) != FunComm.SIO_OK) //{//流控制 // str = FunComm.MxShowError(ret); // MessageBox.Show(str, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} //if ((ret = FunComm.sio_DTR(port, (FunComm.myCOMMDATA[COM].Dtr ? 1 : 0))) != FunComm.SIO_OK) //{//DTR控制 // str =FunComm. MxShowError(ret); // MessageBox.Show(str, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} //if (!FunComm.myCOMMDATA[COM].Hw) //{ // if ((ret = FunComm.sio_RTS(port, (FunComm.myCOMMDATA[COM].Rts ? 1 : 0))) !=FunComm. SIO_OK) // {//Hw控制 // str = FunComm.MxShowError(ret); // MessageBox.Show(str, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; // } //} // tout = 1000 / sio_getbaud(port); /* ms/byte */ // if (tout < 1) // tout = 1; // tout = tout * 1 * 3; /* 1 byte; '*3' is for delay */ // if(tout<100) // tout = 100; //sio_SetWriteTimeouts(port, tout); //ShowStatus(); //return true; }