From: Shusaku Date: 2003-01-07T11:13:21+09:00 Subject: Re: Windows Serial Port On Mon, 06 Jan 2003 20:51:47 GMT Travis Whitton wrote: > Is there a way to access the serial port using Ruby and Windows? If so, > can someone point me to some examples? require 'Win32API' NULL = 0 GENERIC_READ = 0x80000000 GENERIC_WRITE = 0x40000000 OPEN_EXISTING = 3 fCreateFile = Win32API.new("kernel32", "CreateFileA", 'PLLLLLL', 'L') fWriteFile = Win32API.new("kernel32", "WriteFile", 'LPLPL', 'L') fReadFile = Win32API.new("kernel32", "ReadFile", 'LPLPL', 'L') hCom = fCreateFile.call("COM3", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL) ptxBytes = [0].pack("L") prxBytes = [0].pack("L") txBuffer = "ATZ\r" rxBuffer = " " * 256 nRet = fWriteFile.call(hCom, txBuffer, txBuffer.size, ptxBytes, NULL) txBytes = ptxBytes.unpack("L")[0] #=> 4 nRet = fReadFile.call(hCom, rxBuffer, rxBuffer.size, prxBytes, NULL) rxBytes = prxBytes.unpack("L")[0] #=> 10 rxBuffer[0...rxBytes] #=> "ATZ\r\r\nOK\r\n" -- Shusaku