Example #1
0
        static void Main(string[] args)
        {
            byte[] byteBuff    = new byte[256];
            byte[] cmdx        = new byte[1];
            byte[] len         = new byte[1];
            const byte  INIT_TAB = 0x00;
            byte   retVal;
            byte[] byteRdBuff  = new byte[256];
            byte[] byteRddBuff = new byte[256];
            int    count=256;

            string[] cmPort;
            int pos,pIndex=0;
            IniParser ini_file;
            string sComPort;
            int speed;
            //System.Timers.Timer myTimer = new System.Timers.Timer();
            StopWatch  sTimer;
            SerialQueue Q   = new SerialQueue();

            //IntPtr windowHandle = (new WindowInteropHelper(this)).Handle;
            //HwndSource src = HwndSource.FromHwnd(windowHandle);
            //src.AddHook(new HwndSourceHook(WndProc));

            // Starts library
            fixed_lib.lStart();

            for(int i=0; i<256; i++)
            {
            Q.PushRxByte((byte)i);
            byteBuff[i]=(byte)(i);
            //System.Console.WriteLine("bytes={0}\r\n",Q.PullRxByte());
            }

            // Initialize tag by passing first argument as zero
            fixed_lib.lPushTag(INIT_TAB,ref byteBuff,0);
            fixed_lib.lPushTag(0xf, ref byteBuff,0);
            fixed_lib.TransmitTag();
            fixed_lib.WaitTag(1000);

            do
            {
            retVal=fixed_lib.lPullTag(ref cmdx,ref len,ref byteBuff);
            if(retVal>0)
            {
                System.Console.WriteLine("cmdx={0} len={1}\r\n",cmdx[0],len[0]);
            }

            }while(retVal>0);
            //

            fixed_lib.lStop();

            return ;

            myTimer          = new System.Timers.Timer();
            myTimer.Elapsed += OnTimedEvent;
            myTimer.Interval = 10;
            myTimer.Enabled  = false;

            for(int i=0; i<256; i++)
            {
            Q.PushRxByte((byte)i);
            byteBuff[i]=(byte)(i+10);
            //System.Console.WriteLine("bytes={0}\r\n",Q.PullRxByte());
            }

            //System.Console.WriteLine("-----------------------------\r\n");
            //Q.PullRx(byteRddBuff,80);
            //System.Console.WriteLine(ByteArrayToHexString(byteRddBuff));
            //Serial_Comm.encodeATEMsg(100,ref byteBuff,10);
            //return;

            const string iniFileName= @"serial.ini";

            using (StreamWriter w = File.AppendText(iniFileName)) ;
            ini_file = new IniParser(iniFileName);

            sTimer=new StopWatch();
            sTimer.Start();

            ini_file.AddSetting("PORTSETTINGS", "COM","1");
            ini_file.AddSetting("PORTSETTINGS", "SPEED","115200");

            ini_file.SaveSettings();

            sComPort   = ini_file.GetSetting("PORTSETTINGS", "COM");

            System.Console.WriteLine(args.Length);

            cmPort = SerialPort.GetPortNames();
            if (cmPort.Length == 0)
            {
            System.Console.WriteLine("No Serial Port Found");
            }
            else
            {
            System.Console.Write("One COM PORT found on system");
            System.Console.Write("Serial Port={0}", cmPort[0]);

            myTimer.Start();
            }

            Thread.Sleep(10000);
            Thread.Sleep(10000);
            Thread.Sleep(10000);
            Thread.Sleep(10000);

            StdOut.WriteLine("This is Main program\r\n");
            StdOut.WriteLine("This is Main program\r\n");
            StdOut.WriteLine("This is Main program\r\n");
            StdOut.WriteLine("This is Main program\r\n");
            StdOut.WriteLine("This is Main program\r\n");

            sTimer.Stop();
            StdOut.WriteLine("StopWatch Timer Val={0}\r\n", sTimer.GetElapsedTime());

            ini_file.SaveSettings();
        }
Example #2
0
    public static void Main()
    {
        byte[] byteBuff  = new byte[256];
        byte cmdx        = 0;
        byte len         = 0;
        const byte  INIT_TAB = 0x00;
        int   retVal;
        SerialQueue Q      = new SerialQueue();

        //Console.WriteLine ("Hello Mono World {0}",fixed_lib.getpid());
        Console.WriteLine ("Hello Mono World");

        // Starts library
        fixed_lib.lStart();

        for(int i=0; i<256; i++)
        {
            Q.PushRxByte((byte)i);
            byteBuff[i]=(byte)(i);
            //System.Console.WriteLine("bytes={0}\r\n",Q.PullRxByte());
        }

        int size = Marshal.SizeOf(byteBuff[0]) * byteBuff.Length;
        IntPtr pnt = Marshal.AllocHGlobal(size);
        Marshal.Copy(byteBuff, 0, pnt, byteBuff.Length);

        // Initialize tag by passing first argument as zero
        fixed_lib.lPushTag(INIT_TAB,pnt,0);
        fixed_lib.lPushTag(0xf,pnt,10);
        fixed_lib.TransmitTag();
        fixed_lib.WaitTag(10);

        do
        {
            retVal=0;

            retVal = fixed_lib.lPullTag(pnt);
            cmdx   = (byte)retVal;

            if(retVal>0)
            {
                cmdx=(byte)retVal;
                len=(byte)(retVal>>8);
                if(cmdx>0)
                {
                    System.Console.WriteLine("cmdx=0x{0:X} len=0x{1:X}\r\n",cmdx,len);
                    Marshal.Copy(pnt,byteBuff,0,byteBuff.Length);

                    for(int i=0;i<len;i++)
                    {
                        System.Console.WriteLine("0x{0:X} ",byteBuff[i]);
                    }
                }
            }
            retVal=cmdx;

        }while(cmdx>0);

        fixed_lib.lStop();
        Marshal.FreeHGlobal(pnt);
    }