Beispiel #1
0
 public InFeed(SerialSettings settings, string switchValue="")
 {
     Port = new SerialPortManager(settings.PortName)
     {
         Settings = settings
     };
     SwitchValue = switchValue;
 }
Beispiel #2
0
 public OutFeed(SerialSettings settings)
 {
     Port = new SerialPortManager(settings.PortName)
     {
         Settings = settings
     };
     _outputMessage = string.Empty;
 }
Beispiel #3
0
        private void InitDut()
        {
            expectedCode = plu + "," + ppk;
            SerialSettings tmpSettings = new SerialSettings()
            {
                PortName = "COM5"
            };

            DUT = new InFeed(tmpSettings)
            {
                Header             = _header,
                Footer             = _footer,
                MessageFormat      = "^[0-9a-zA-z]{6,6}$",//"^[0-9a-zA-z]{6,6},[0-9]{4,4} $",
                CheckMessageFormat = false
            };
        }
        private void InitDut()
        {
            inputMessage = inplu + "," + inppk;
            SerialSettings tmpSettings = new SerialSettings()
            {
                PortName = "COM5"
            };

            DUT = new OutFeed(tmpSettings)
            {
                Header          = _outheader,
                Footer          = _outfooter,
                InputPLULength  = inputPLULen,
                InputPPKLength  = inputPPKLen,
                OutputPLULength = outputPLULen,
                OutputPPKLength = outputPPKLen,
                FixedAsciiData  = fixeddata
            };
            expectedData = outplu + outppk + fixeddata;
        }
Beispiel #5
0
        public static bool InitializePorts()
        {
            SerialSettings comSettings;

            LineInFeeds = new List <InFeed>();
            string[] section = new string[] { "LineInFeed1", "LineInFeed2", "OutFeed" };
            for (int i = 1; i <= section.Length; i++)
            {
                int j = i - 1;
                PrintLog("Setting " + section[j]);
                try
                {
                    comSettings = new SerialSettings()
                    {
                        PortName = ini.GetSettingString("COMPort", "COM" + i.ToString(), section[j]),
                        BaudRate = ini.GetSettingInteger("Baudrate", 9600, section[j]),
                        DataBits = ini.GetSettingInteger("Databits", 8, section[j]),
                        Parity   = (Parity)(Enum.Parse(typeof(Parity), ini.GetSettingString("Parity", "None", section[j]))),
                        StopBits = (StopBits)ini.GetSettingInteger("StopBits", 1, section[j])
                    };
                    if (i < section.Length) // InFeed
                    {
                        InFeed tmpInFeed = new InFeed(comSettings, ini.GetSettingString("SwitchValue", "0" + i.ToString(), section[j]))
                        {
                            Header        = StringUtils.ParseIntoASCII(ini.GetSettingString("Header", "", section[j])),
                            Footer        = StringUtils.ParseIntoASCII(ini.GetSettingString("Footer", "", section[j])),
                            MessageFormat = ini.GetSettingString("MessageFormat", "", section[j]),
                            PLULength     = ini.GetSettingInteger("PLULength", 6, section[j]),
                            PPKLength     = ini.GetSettingInteger("PPKLength", 5, section[j])
                        };
                        LineInFeeds.Add(tmpInFeed);

                        if (i == 1)
                        {
                            LineInFeeds[j].Port.NewSerialDataReceived += new EventHandler <SerialDataEventArgs>(LineInFeed1NewDataReceived);
                        }
                        if (i == 2)
                        {
                            LineInFeeds[j].Port.NewSerialDataReceived += new EventHandler <SerialDataEventArgs>(LineInFeed2NewDataReceived);
                        }
                    }
                    else  // OutFeed
                    {
                        LineOutFeed = new OutFeed(comSettings)
                        {
                            Header          = StringUtils.ParseIntoASCII(ini.GetSettingString("Header", "", section[j])),
                            Footer          = StringUtils.ParseIntoASCII(ini.GetSettingString("Footer", "", section[j])),
                            OutputPLULength = ini.GetSettingInteger("PLULength", 6, section[j]),
                            OutputPPKLength = ini.GetSettingInteger("PPKLength", 5, section[j]),
                            FixedAsciiData  = ini.GetSettingString("FixedAsciiData", "abcdef", section[j])
                        };
                        LineOutFeed.Port.NewSerialDataReceived += new EventHandler <SerialDataEventArgs>(LineOutFeedNewDataReceived);
                    }
                }
                catch (Exception e)
                {
                    ErrorMessage(String.Format("Failed setting serial {0} settings: {1}{2}.", section[j], e.Message, exitPrompt));
                    return(false);
                }
            }

            string _section  = "InFeedSwitch";
            string switchStr = ini.GetSettingString("ShortDesc", "Infeed switch", _section);

            PrintLog("Setting " + switchStr);
            try
            {
                SocketTransactorType cxnType = (ini.GetSettingString("Sockettype", "SERVER", _section).ToUpper() == "SERVER") ?
                                               SocketTransactorType.server : SocketTransactorType.client;
                InFeedSwitch = new TcpConnection(cxnType,
                                                 ini.GetSettingString("IPAddress", "0.0.0.0", _section),
                                                 (uint)ini.GetSettingInteger("PortNumber", 0, _section))
                {
                    MaxNumConnections = ini.GetSettingInteger("MaxNumberConnections", 1, _section),
                    Header            = StringUtils.ParseIntoASCII(ini.GetSettingString("Header", "", _section)),
                    Footer            = StringUtils.ParseIntoASCII(ini.GetSettingString("Footer", "", _section))
                };
                int timeout = ini.GetSettingInteger("TimeoutSec", 30, _section) * 1000;
                if (timeout > 0)
                {
                    useTimer                   = true;
                    timeout                   += 100; // allow a 100ms allowance
                    InFeedSwitchTimer          = new System.Timers.Timer(timeout);
                    InFeedSwitchTimer.Elapsed += OnInFeedSwitchTimeout;
                }
                InFeedSwitch.TcpConnected    += new TcpEventHandler(InFeedSwitchConnectedListener);
                InFeedSwitch.TcpDisconnected += new TcpEventHandler(InFeedSwitchDisconnectedListener);
                InFeedSwitch.DataReceived    += new TcpEventHandler(InFeedSwitchDataReceiver);
            }
            catch (Exception e)
            {
                ErrorMessage(String.Format("Failed setting {0} settings: {1}", switchStr, e.Message));
                return(false);
            }

            HeartbeatMessage = ini.GetSettingString("HeartbeatMessage", "xxxx", _section);
            return(true);
        }