public smartrack[] loadDevices(SerialCOMPort port) { try { smartrack[] restoredAccount; //Stream myFileStream = File.OpenRead(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + @"\text.txt"); Stream myFileStream = File.OpenRead(path + @"vehicle"); BinaryFormatter deserializer = new BinaryFormatter(); restoredAccount = (smartrack[])(deserializer.Deserialize(myFileStream)); myFileStream.Close(); for (int i = 0; i < restoredAccount.Length; i++) { if (restoredAccount[i] != null) { port.mainFrm = this; restoredAccount[i].serialPort = port; } } return restoredAccount; } catch { return null; } }
public smartrack(SerialCOMPort port,string device_number) { this.serialPort = port; this.device_number = device_number; this.Bersaglio = null; }
/*******************************/ private void Form1_Load(object sender, EventArgs e) { if (frmMapPoint == null) { frmMapPoint = new frmMapPoint(); frmMapPoint.mainFrm = this; frmMapPoint.Show(); frmMapPoint.loadMap(); } if (frmSatelliteMap == null) { frmSatelliteMap = new frmMap(); frmSatelliteMap.satelliteMap.Navigate(@AppDomain.CurrentDomain.BaseDirectory + "map.htm"); frmSatelliteMap.satelliteMap.Document.InvokeScript("SetMapStyle", new object[] { "VEMapStyle.Hybrid" }); //frmSatelliteMap.Show(); } if (frmAllarm == null) { frmAllarm = new frmAllarm(); frmAllarm.mainFrm = this; frmAllarm.Show(); } port = null; receiveNow = new AutoResetEvent(false); if (CommSetting.comm != null && CommSetting.comm.IsOpen()) { CommSetting.comm.Close(); CommSetting.comm = null; } if (loadOptions()) { try { this.portf = OpenPort("COM" + COM_PORT); Cursor.Current = Cursors.WaitCursor; // Check connection try { ExecCommand("AT", 300, "No phone connected at COM" + COM_PORT + "."); } catch { string command = " " + char.ConvertFromUtf32(26) + "\r"; ExecCommand(command, 3000, "Failed to send message"); //3 seconds ExecCommand("AT", 300, "No phone connected"); } // Use message format "Text mode" ExecCommand("AT+CMGF=1", 300, "Failed to set message format."); // Use character set "ISO 8859-1" ExecCommand("AT+CSCS=\"8859-1\"", 300, "Failed to set character set."); // Select SIM storage ExecCommand("AT+CPMS=\"SM\"", 300, "Failed to select message storage."); //sendMsg("3486526983", "Messaggio di prova"); } catch(Exception ex) { Output(ex.Message); } } else { options opt = new options(); opt.mainFrm = this; loadOptions(); opt.textBox1.Text = COM_PORT; opt.textBox2.Text = COM_SPEED; opt.textBox3.Text = COM_TIMEOUT; opt.textBox4.Text = SMS_C; opt.ShowDialog(); try { this.portf = OpenPort("COM" + COM_PORT); Cursor.Current = Cursors.WaitCursor; // Check connection ExecCommand("AT", 300, "No phone connected at " + "COM20" + "."); // Use message format "Text mode" ExecCommand("AT+CMGF=1", 300, "Failed to set message format."); // Use character set "ISO 8859-1" ExecCommand("AT+CSCS=\"8859-1\"", 300, "Failed to set character set."); // Select SIM storage ExecCommand("AT+CPMS=\"SM\"", 300, "Failed to select message storage."); // sendMsg("+393486526983", "Messaggio di prova"); } catch { } } port = new SerialCOMPort(); loadDevices(); //Carica i dispositivi da file StopRcvSMS = false; StartSend = false; Thread smsRcv = new Thread(checkSMS); smsRcv.Start(); Thread listen = new Thread(listenClient); listen.Start(); updateConnectionString(); }
public smartrack(SerialCOMPort port, string device_number) { this.serialPort = port; this.device_number = device_number; this.Bersaglio = null; }