Results 1 to 3 of 3

Thread: librs232 - plugin for the serial port access

  1. #1
    Join Date
    May 2012
    Location
    Moscow, Russia
    Posts
    661
    Mentioned
    35 Post(s)
    Quoted
    102 Post(s)

    Default librs232 - plugin for the serial port access

    Hi. Today I present to you the plugin for the serial port access. Provides functions for working with a serial port. Allows you to work with a serial port from a script.
    Based on the TBlockSerial by Lukas Gebauer, documentation can be found here: http://synapse.ararat.cz/doc/help/sy...ockSerial.html

    Test script:
    Simba Code:
    program rs232test;

    {$loadlib librs232.dll}

    const
      {:stopbit value for 1 stopbit}
      SB1 = 0;
      {:stopbit value for 1.5 stopbit}
      SB1andHalf = 1;
      {:stopbit value for 2 stopbits}
      SB2 = 2;

      Data = '<?xml version="1.0" encoding="UTF-8"?><ArmRequest><RequestBody><ProtocolLabel>OFDFNARMUKM</ProtocolLabel><ProtocolVersion>10.4</ProtocolVersion><RequestId>{305a5e44-42cd-4e33-86fb-258950ee11b5}</RequestId><DateTime>2017-05-18 19:44:06</DateTime><Command>2</Command></RequestBody><RequestData><![CDATA[]]></RequestData></ArmRequest>';

    procedure RS232Test();
    var
     ComPort: TComPort;
     Answer,version: ansistring;
    begin
     answer:='';
     WriteLn('Simba Inbuilt RS232 test');
     ComPort.Init();
     try
      ComPort.Connect('COM9');
      sleep(1000);
      ComPort.Config(115200, 8, 'N', SB1, True, False);
      Sleep(1000);
      if ComPort.GetLastError() <> 0 then
       begin
        WriteLn('RS232 Error: ' + ComPort.GetLastErrorDesc());
        TerminateScript();
      end;
      version := ComPort.GetVersion();
      WriteLn('version: ' + version);
      ComPort.SendString(Data + #13#10);
      if ComPort.GetLastError() <> 0 then
        begin
         WriteLn('RS232 Send Error: ' + ComPort.GetLastErrorDesc());
         TerminateScript();
        end;
       WriteLn('Send data: ' + Data);

       while (answer = '') do
        begin
          answer := ComPort.RecvPacket(5000);
          Sleep(10);
        end;
       WriteLn('Got answer: '+ answer);
       WriteLn('Test passed.');
     finally
      ComPort.Free();
     end;
    end;

    begin
     RS232Test();
    end.

    Test output:
    Simba Code:
    Successfully saved: C:\Simba\Scripts\rs232test.simba
    Compiled succesfully in 62 ms.
    Simba Inbuilt RS232 test
    version: SynaSer 7.6.0
    Send data: <?xml version="1.0" encoding="UTF-8"?><ArmRequest><RequestBody><ProtocolLabel>OFDFNARMUKM</ProtocolLabel><ProtocolVersion>10.4</ProtocolVersion><RequestId>{305a5e44-42cd-4e33-86fb-258950ee11b5}</RequestId><DateTime>2017-05-18 19:44:06</DateTime><Command>2</Command></RequestBody><RequestData><![CDATA[]]></RequestData></ArmRequest>
    Got answer: <?xml version="1.0" encoding="UTF-8"?><ArmResponse>   <ResponseBody>      <ProtocolLabel>OFDFNARMUKM</ProtocolLabel>      <ProtocolVersion>10.1</ProtocolVersion>      <RequestId>{eddff3d7-6aea-4c2d-a91f-03c29efdbe42}</RequestId>      <Result>0</Result>      <ErrorCategory>0</ErrorCategory>      <ErrorSource>FN_CONTROLLER</ErrorSource>      <ErrorCode>0</ErrorCode>      <ErrorDescription />      <Command>3</Command>   </ResponseBody>   <ResponseData><![CDATA[<ArmGetStatus><LastCommand>0</LastCommand><LastCommandStatus>25</LastCommandStatus><LastCommandExecTime>26</LastCommandExecTime><NetworkInterface>eth0   MAC=B8:27:EB:55:6A:8A   IP=</NetworkInterface><PaperWidth>40</PaperWidth><KKTFWVersion>008.09</KKTFWVersion><FNStatus><LifePhase>1</LifePhase><CurrentDocType>0</CurrentDocType><CurrentDocData>0</CurrentDocData><ShiftState>0</ShiftState><StatusNeedChange>0</StatusNeedChange><StatusEndingResource>0</StatusEndingResource><StatusOverflow>0</StatusOverflow><StatusOverdueSending>0</StatusOverdueSending><LastDocDateTime></LastDocDateTime><LastDocNumber>0</LastDocNumber><FactoryNum>8710000100197089</FactoryNum><ExpirationDate></ExpirationDate><FWVersion>fn_v_1_0</FWVersion></FNStatus><OFDStatus><ExchangeStatus>0</ExchangeStatus><MessageReadStarted>0</MessageReadStarted><QueueLength>0</QueueLength><FirstQueueDocNumber>0</FirstQueueDocNumber><FirstQueueDocDateTime></FirstQueueDocDateTime></OFDStatus></ArmGetStatus>]]></ResponseData></ArmResponse>
    Test passed.
    Succesfully executed in 2063 ms.

    So, now an issue 407 from the github is done.
    Enjoy
    Attached Files Attached Files
    Per aspera ad Astra!
    ----------------------------------------
    Slow and steady wins the race.

  2. #2
    Join Date
    Jul 2009
    Posts
    166
    Mentioned
    5 Post(s)
    Quoted
    69 Post(s)

    Default

    Look like lots of work has gone into it. But does modern computers even have serial ports :S I have seen those usb to serial things, maybe with those.

  3. #3
    Join Date
    May 2012
    Location
    Moscow, Russia
    Posts
    661
    Mentioned
    35 Post(s)
    Quoted
    102 Post(s)

    Default

    Yes, with the virtual serial port its works too
    Per aspera ad Astra!
    ----------------------------------------
    Slow and steady wins the race.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •