Free: Serial Port Action plugin

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • webultra
    Forum Member
    • Mar 2007
    • 225

    #31
    I know this maybe could be to older...but I think it could help someone. It's a modded version source code of this plugin. I think it's easier to understand and use.

    Code:
    SerialPort = {Stored = {}};
    SerialPort.Version = 1.3;
    function SerialPort.Init(portNumber)
       local axComPort={}
       netms=0
       axComPort[portNumber]=luacom.CreateObject("NETCommOCX.NETComm")
       if (axComPort[portNumber]==nil) then
           axComPort[portNumber]=luacom.CreateObject("MSCommLib.MSComm")
           if (axComPort[portNumber]==nil) then
               --return false
               return nil;
           else
               netms=1
               axComPort[portNumber].CommPort=portNumber
               return axComPort[portNumber];
               --return true
           end
       else
           axComPort[portNumber].CommPort=portNumber
           return axComPort[portNumber];
           --return true
       end
    end
    -------------------------------------------------------
    function SerialPort.TerminateAll(handle)
       handle=nil
    end
    -------------------------------------------------------
    function SerialPort.Terminate(handle)
       handle.PortOpen=false
       handle=nil
    end
    -------------------------------------------------------
    function SerialPort.Open(handle, port)
       --local oldPort = handle.CommPort
       handle.CommPort=port;
       handle.PortOpen=true;
       return handle.PortOpen;
       --handle.CommPort = oldPort
    end
    -------------------------------------------------------
    function SerialPort.IsOpen(handle)
       return handle.PortOpen
    end
    -------------------------------------------------------
    function SerialPort.Close(handle, port)
       --local oldPort = handle.CommPort
       handle.CommPort=port
       handle.PortOpen=false
       --handle.CommPort = oldPort
       return handle.PortOpen
    end
    -------------------------------------------------------
    function SerialPort.SetSettings(handle,nBauds,nParity,nDatabit,nStopbit,nFlowcontrol)
       handle.Settings=nBauds..nParity..nDatabit..nStopbit..nFlowcontrol
    end
    -------------------------------------------------------
    function SerialPort.ListAvaliblePorts(handle,nStart,nEnd)
       local ports={}
       local oldPort = handle.CommPort
       for x = nStart, nEnd do
          if x ~= 4 and x~= 5 then
             handle.CommPort=x
              if (handle.PortOpen==true) then
                 --port is already open
              else
                 handle.PortOpen=true
                 if (handle.PortOpen==true) then
                      Table.Insert(ports, Table.Count(ports)+1, x);
                      handle.PortOpen=false
                   end
              end
          end
       end
       if Table.Count(ports)>1 then
          return ports
       else
          return nil;
       end
    end
    
    function SerialPort.SetP(handle, port)
       handle.CommPort=port
    end
    function SerialPort.CleanBufferCount(handle)
       handle.InBufferCount = 0;
    end
    -------------------------------------------------------
    function SerialPort.SetRTS(handle, nRTS)
       handle.RTSEnable=nRTS
    end
    -------------------------------------------------------
    function SerialPort.SetDTR(handle, nDTR)
       handle.DTREnable=nDTR
    end
    -------------------------------------------------------
    function SerialPort.GetRTS(handle)
       return handle.RTSEnable
    end
    -------------------------------------------------------
    function SerialPort.GetDTR(handle)
       return handle.DTREnable
    end
    -------------------------------------------------------
    function SerialPort.Output(handle,sOutput,nBreak)
       if (nBreak==true) then
          sOutput=sOutput..String.Char(13)
       end
       handle.Output=sOutput
    end
    -------------------------------------------------------
    function SerialPort.Input(handle)
       if (netms==1) then
          return handle.Input
       else
          return handle.InputData
       end
    end
    -------------------------------------------------------
    function SerialPort.BufferCount(handle)
       return handle.InBufferCount
    end
    -------------------------------------------------------
    function SerialPort.InputLen(handle)
       return handle.InputLen
    end
    -------------------------------------------------------
    function SerialPort.RegisterMscomm()
       bOK = Registry.DoesKeyExist(HKEY_CLASSES_ROOT,"CLSID\\{648A5600-2C6E-101B-82B6-000000000014}\\InprocServer32");
       if (bOK) then
          return false
       else
          PSDK.ExportArchive(3000, "AutoPlay\\Docs\\mscomm.ocx");
          System.RegisterActiveX("AutoPlay\\Docs\\mscomm.ocx");
          return true
       end
    end
    -------------------------------------------------------
    function SerialPort.RegisterNetComm()
       bOK = Registry.DoesKeyExist(HKEY_CLASSES_ROOT,"CLSID\\{53867031-6B4D-4F7D-B089-5DFEC731F5FA}\\InprocServer32");
       if (bOK) then
          return false
       else
          PSDK.ExportArchive(3001, "AutoPlay\\Docs\\netcomm.ocx");
          System.RegisterActiveX("AutoPlay\\Docs\\netcomm.ocx");
          return true
       end
    end

    Comment

    • albaloops
      Forum Member
      • Jun 2012
      • 20

      #32
      Hi
      I Need this plugin for AMS 8.x
      Thanks

      Comment

      Working...
      X