public override void SendMessage(CNCMessage message, bool logging = true) { if (AutoPoll) { MessageBuffer.Add(message); OnMessageSent(this, message); } else { try { SerialInterface.WriteLine(message.Message); } catch (InvalidOperationException ex) { AddToSendReceiveBuffer(ex.Message); return; } } if (logging) { AddToSendReceiveBuffer(message.Message); } }
public void init() { node = new SerialInterface("COM"); node.init(); node.NewReadException += new Viper.NewViperReadException(node_NewReadException); node.NewSingleNodeStatus += new SerialInterface.NewViperNodeStatus(node_NewSingleNodeStatus); }
public bool Initialize(string port_progbox, string port_charger) { bool result = true; if (!m_initialized) { ProgboxIf = new SerialInterface(port_progbox, globals.baud, Parity.None, 8); ChargerIf = new SerialInterface(port_charger, globals.baud, Parity.None, 8); Progbox = new Target(); Charger = new Target(); ProgboxIf.RegisterListener(this); ChargerIf.RegisterListener(this); if (!ProgboxIf.Open() || !ChargerIf.Open()) { result = false; ProgboxIf.Close(); ChargerIf.Close(); ProgboxIf.Dispose(); ChargerIf.Dispose(); } else { m_initialized = true; } } return(result); }
private void connectButton_Click(object sender, RoutedEventArgs e) { if (comPortComboBox.SelectedItem != null) { comPort = ((ComboBoxItem)comPortComboBox.SelectedItem).Content.ToString(); if (comPort == String.Empty) { MessageBox.Show("Geen comport geselecteerd."); return; } Serial = new SerialInterface(comPort, 115200); Serial.OpenPort(); if (Serial.IsOpen) { Serial.SerialDataEvent += Serial_SerialDataEvent; controlsFysiologieStackPanel.IsEnabled = true; connectButton.IsEnabled = false; comPortComboBox.IsEnabled = false; } else { controlsFysiologieStackPanel.IsEnabled = false; connectButton.IsEnabled = true; comPortComboBox.IsEnabled = true; } } }
public ChannelHandler(uint myChannel, Type Serializable, bool loggedInOnly) { LoggedInOnly = loggedInOnly; ChannelID = myChannel; if (Serializable != typeof(void)) { processor = SerialInterface.Build(Serializable); } }
/// <summary> /// Initializes scanner from communication port to serial port by providing locker configuration. /// </summary> /// <returns> /// Publish scanning value to MQTT Broker /// </returns> public static void InitializeScanner(ComPortsHealthCheck comPortsHealthCheck, AppSettings lockerConfiguration, Func <string, string> dataProcessFunc) { if (comPortsHealthCheck.IsScannernPortAvailable) { SerialInterface controllerModule = lockerConfiguration.Microcontroller.Scanner; SerialPortControlService scanner = new SerialPortControlService(new SerialPortResource(controllerModule.Port, controllerModule.Baudrate, controllerModule.DataBits, 500, 500)); scanner.SetReadToPublishHandler(controllerModule, dataProcessFunc); scanner.Begin(); Log.Information("[HCM][Communication Port Control Service][Initialize Scanner]" + "[Scanner Port : " + controllerModule.Port + "]"); } }
private static bool Check(SerialInterface portInterface) { bool flag = false; var spService = new SerialPortBaseService(); if (spService.IsPortPresented(portInterface.Port)) { flag = !spService.IsPortOpened(portInterface); } return(flag); }
public void setSerialPort(SerialInterface mSerialInterface) { if (_serialPort != null) { //设置触发DataReceived事件的字节数为1 _serialPort.ReceivedBytesThreshold = 1; //接收到一个字节时,也会触发DataReceived事件 _serialPort.DataReceived += new SerialDataReceivedEventHandler(mSerialInterface.OnDataReceived); //接收数据出错,触发事件 _serialPort.ErrorReceived += null; } }
public override void CloseConnection() { try { SerialInterface.Close(); PortClosed(Portname, SerialInterface.BaudRate); } catch (Exception) { ClosePortFailed(this, new EventArgs()); } }
/// <summary> /// Test serial port available. /// </summary> /// <returns> /// Nothing returned but error throw when its error /// </returns> public bool IsPortOpened(SerialInterface controlModuleObj) { try { var controlModule = new SerialPortControlService(new SerialPortResource(controlModuleObj.Port, controlModuleObj.Baudrate, controlModuleObj.DataBits, 500, 500)); return(controlModule.IsOpen()); } catch (Exception) { throw; } }
/// <summary> /// Reads to set locker and name. /// </summary> /// <returns> /// Get list of byte. /// </returns> public void SetReadToPublishHandler(SerialInterface controllerModule, Func <string, string> dataProcessingFunc) { try { _serialPort.DataReceived += new SerialDataReceivedEventHandler(SerialInputEventHandler); _SerialDataProcessing = dataProcessingFunc; _SerialDataEventName = controllerModule.Name; Log.Debug("[HCM][SerialPort Control Service][Set Read Handler]" + "[Port : " + _serialPort.PortName + "]" + "[Event Name : " + _SerialDataEventName + "]"); } catch (Exception) { throw; } }
public ChannelSender(Type t) { processor = SerialInterface.Build(t); }
public RealityCoprocessor(Nintendo64 nintendo64) { this.nintendo64 = nintendo64; SP = new SignalProcessor(this); DP = new DisplayProcessor(this); PI = new ParallelInterface(this); SI = new SerialInterface(this); AI = new AudioInterface(this); VI = new VideoInterface(this); MI = new MIPSInterface(this); RI = new RDRAMInterface(this); MemoryMaps = new[] { new MappingEntry(0x00000000, 0x03FFFFFF, false) { Read = nintendo64.RAM.MemoryMaps.ReadWord, Write = nintendo64.RAM.MemoryMaps.WriteWord }, new MappingEntry(0x04000000, 0x040FFFFF, false) { Read = SP.MemoryMaps.ReadWord, Write = SP.MemoryMaps.WriteWord }, new MappingEntry(0x04100000, 0x041FFFFF, false) { Read = DP.MemoryMaps.ReadWord, Write = DP.MemoryMaps.WriteWord }, new MappingEntry(0x04300000, 0x043FFFFF, false) { Read = MI.MemoryMaps.ReadWord, Write = MI.MemoryMaps.WriteWord }, new MappingEntry(0x04400000, 0x044FFFFF, false) { Read = VI.MemoryMaps.ReadWord, Write = VI.MemoryMaps.WriteWord }, new MappingEntry(0x04500000, 0x045FFFFF, false) { Read = AI.MemoryMaps.ReadWord, Write = AI.MemoryMaps.WriteWord }, new MappingEntry(0x04600000, 0x046FFFFF, false) { Read = PI.MemoryMaps.ReadWord, Write = PI.MemoryMaps.WriteWord }, new MappingEntry(0x04700000, 0x047FFFFF, false) { Read = RI.MemoryMaps.ReadWord, Write = RI.MemoryMaps.WriteWord }, new MappingEntry(0x04800000, 0x048FFFFF, false) { Read = SI.MemoryMaps.ReadWord, Write = SI.MemoryMaps.WriteWord }, new MappingEntry(0x10000000, 0x1FBFFFFF, false) { Read = PI.MemoryMaps.ReadWord }, new MappingEntry(0x1FC00000, 0x1FC007FF, false) { Read = SI.MemoryMaps.ReadWord, Write = SI.MemoryMaps.WriteWord } }; }
public override CNCMessage ReceiveMessage(int TimeOut = 100, bool logging = true) { CNCMessage rmessage = new CNCMessage(); LastMessageReceived = null; try { if (SerialInterface.ReadTimeout != TimeOut) { SerialInterface.ReadTimeout = TimeOut; } if (SerialInterface.BytesToRead >= 0) { rmessage.Message = SerialInterface.ReadLine(); } LastMessageReceived = rmessage; OnMessageReceived(this, rmessage); } catch (TimeoutException ex) { rmessage.Message = "TIMEOUT"; return(rmessage); } catch (InvalidOperationException ex) { rmessage.Message = ex.Message; CloseConnection(); if (logging) { AddToSendReceiveBuffer(rmessage.Message); } return(rmessage); } catch (ArgumentOutOfRangeException ex) { rmessage.Message = ex.Message; if (logging) { AddToSendReceiveBuffer(rmessage.Message); } return(rmessage); } catch (IndexOutOfRangeException ex) { // This happens if while this thread is reading bytes from SerialPort, a other // thread is reading the bytes from port. this can then result in an -1 data pointer // (SerialPort is not thread save). // The good news are; this only means the message was already read from port and nothing // else is to do. Debugger.Break(); rmessage.Message = "-"; return(rmessage); } catch (OverflowException ex) { // This happens if while this thread is reading bytes from SerialPort, a other // thread is reading the bytes from port. this can then result in an -1 data pointer // (SerialPort is not thread save). // The good news are; this only means the message was already read from port and nothing // else is to do. //Debugger.Break(); rmessage.Message = "-"; return(rmessage); } catch (IOException ex) { // The I/O operation has been aborted because of either a thread exit or an application request.\r\n Debugger.Break(); rmessage.Message = "-"; return(rmessage); } if (logging) { AddToSendReceiveBuffer(rmessage.Message); } return(rmessage); }
protected override void listen() { bool readPayload = false; int channel = 0; int size = 0; byte[] payload; int received = 0; byte[] headerBuffer = new byte[8]; while (doListen || connected) { try { //Wait for 8 bytes if (!readPayload) { received = 0; while (received < 8) { received += clientStream.Read(headerBuffer, received, 8 - received); } channel = BitConverter.ToInt32(headerBuffer, 0); size = BitConverter.ToInt32(headerBuffer, 4); readPayload = true; } else if (readPayload) { received = 0; payload = new byte[size]; while (received < size) { received += clientStream.Read(payload, received, size - received); } byte[] data = new byte[8 + size]; BitConverter.GetBytes(channel).CopyTo(data, 0); BitConverter.GetBytes(size).CopyTo(data, 4); payload.CopyTo(data, 8); if (initializing) { if (channel == (int)ChannelID.Hello) { SerialInterface proc = SerialInterface.Build(typeof(Result)); Result r = (Result)proc.Deserialize(payload, size); if (r.success == false) { disconnect(); return; } joinAsSpectator(); } else if (channel == (int)ChannelID.ClientFaction) { SerialInterface proc = SerialInterface.Build(typeof(ClientFactionResponse)); ClientFactionResponse r = (ClientFactionResponse)proc.Deserialize(payload, size); host.planetConfig = r.planetConfig; initializing = false; } else if (channel == (int)ChannelID.PhaseChange) { host.phase = data; } } else { if (channel == (int)ChannelID.PhaseChange) { host.phase = data; } if (channel != 2) { buffer.add(data); //server.sendToClients(data, data.Length); //TODO Redirect to analytics } } readPayload = false; } Thread.Sleep(1); } catch (Exception e) { Log.error("Error while reading data from client.", this); Log.error(e.Message, this); this.disconnect(); } } }
public void init() { node = new MasterSerialInterface("COM3"); node.init(); node.NewReadException += new Viper.NewViperReadException(node_NewReadException); }