Пример #1
0
        public void OpenCloseChannel()
        {
            UInt32 deviceID;
            Int32  status = NativeOpenPort20.PassThruOpen(null, out deviceID);

            TraceStatus("PassThruOpen", status);

            Trace.WriteLine("Device ID: " + deviceID);

            UInt32 channelID;

            status = NativeOpenPort20.PassThruConnect(
                deviceID,
                (UInt32)PassThruProtocol.Iso9141,
                (UInt32)PassThruConnectFlags.Iso9141NoChecksum,
                (UInt32)PassThruBaudRate.Rate4800,
                out channelID);
            TraceStatus("PassThruConnect", status);

            Trace.WriteLine("Channel ID: " + channelID);

            status = NativeOpenPort20.PassThruDisconnect(channelID);
            TraceStatus("PassThruDisconnect", status);

            status = NativeOpenPort20.PassThruClose(deviceID);
            TraceStatus("PassThruClose", status);
        }
Пример #2
0
        public void OpenCloseDevice()
        {
            UInt32 deviceID;
            Int32  status = NativeOpenPort20.PassThruOpen(null, out deviceID);

            TraceStatus("PassThruOpen", status);

            Trace.WriteLine("Device ID: " + deviceID);

            status = NativeOpenPort20.PassThruClose(deviceID);
            TraceStatus("PassThruClose", status);
        }
Пример #3
0
        public void SendReceiveLowLevelApi()
        {
            UInt32 deviceID;
            Int32  status = NativeOpenPort20.PassThruOpen(null, out deviceID);

            TraceStatus("PassThruOpen", status);
            Trace.WriteLine("Device ID: " + deviceID);

            UInt32 channelID;

            status = NativeOpenPort20.PassThruConnect(
                deviceID,
                (UInt32)PassThruProtocol.Iso9141,
                (UInt32)PassThruConnectFlags.Iso9141NoChecksum,
                (UInt32)PassThruBaudRate.Rate4800,
                out channelID);
            TraceStatus("PassThruConnect", status);
            Trace.WriteLine("Channel ID: " + channelID);

            SetConfiguration P1Max      = new SetConfiguration(SetConfigurationParameter.P1Max, 2);
            SetConfiguration P3Min      = new SetConfiguration(SetConfigurationParameter.P3Min, 0);
            SetConfiguration P4Min      = new SetConfiguration(SetConfigurationParameter.P4Min, 0);
            SetConfiguration Terminator = new SetConfiguration(SetConfigurationParameter.FinalParam, 0);

            // TODO: add loopback=1
            SetConfiguration[] setConfigurationArray = new SetConfiguration[] { P1Max, P3Min, P4Min };
            using (SetConfigurationList setConfigurationList = new SetConfigurationList(setConfigurationArray))
                //IntPtr buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(SetConfiguration) * setConfigurationArray.Length);
                //IntPtr buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(setConfigurationList));
                //{
                status = NativeOpenPort20.PassThruIoctl(
                    channelID,
                    PassThruIOControl.SetConfig,
                    ref setConfigurationArray,//setConfigurationList.Pointer,
                    IntPtr.Zero);
            //}
            //Marshal.FreeCoTaskMem(buffer);

            TraceStatus("PassThruIoCtl SetConfig", status);

            UInt32      filterID;
            PassThruMsg maskMsg = new PassThruMsg(PassThruProtocol.Iso9141);

            //maskMsg.ExtraDataIndex = 1;
            maskMsg.DataSize = 1;

            status = NativeOpenPort20.PassThruStartMsgFilter(
                channelID,
                (UInt32)PassThruFilterType.Pass,
                maskMsg,
                maskMsg,
                null,
                out filterID);
            TraceStatus("PassThruStartMsgFilter", status);
            Trace.WriteLine("Filter ID: " + filterID);

            byte[]      messageBytes   = new byte[] { 0x80, 0x10, 0xF0, 0x01, 0xBF, 0x40 };
            PassThruMsg initRequestMsg = new PassThruMsg(PassThruProtocol.Iso9141);

            initRequestMsg.ProtocolID = PassThruProtocol.Iso9141;
            initRequestMsg.DataSize   = (UInt32)messageBytes.Length;
            for (int i = 0; i < messageBytes.Length; i++)
            {
                initRequestMsg.Data[i] = messageBytes[i];
            }

            PassThruMsg[] initRequestMsgs = new PassThruMsg[] { initRequestMsg };
            UInt32        numMsgs         = 1;

            status = NativeOpenPort20.PassThruWriteMsgs(
                channelID,
                initRequestMsgs,
                ref numMsgs,
                500);
            TraceStatus("PassThruWriteMsgs", status);

            PassThruMsg received = new PassThruMsg(PassThruProtocol.Iso9141);

            PassThruMsg[] receivedMessages = new PassThruMsg[] { received };
            numMsgs = 1;
            status  = NativeOpenPort20.PassThruReadMsgs(
                channelID,
                receivedMessages,
                ref numMsgs,
                500);
            TraceStatus("PassThruReadMsgs", status);

            if (status == (UInt32)PassThruStatus.NoError)
            {
                for (int i = 0; i < received.DataSize; i++)
                {
                    Trace.Write(received.Data[i].ToString());
                    Trace.Write(' ');
                }
            }

            status = NativeOpenPort20.PassThruDisconnect(channelID);
            TraceStatus("PassThruDisconnect", status);

            status = NativeOpenPort20.PassThruClose(deviceID);
            TraceStatus("PassThruClose", status);
        }