require "dl/import" module DXLIB2 extend DL::Importer dlload "./dxlib2.dll" extern "int DX_OpenPort( char *, long )" extern "int DX_Active( int )" extern "int DX_Ping( int, unsigned char, int, unsigned short * )" extern "int DX_ClosePort( int )" end comport = "\\\\.\\COM3" br = 1000000 timeout = 50 terr = ' ' * 2 mark = "\n" devid = DXLIB2.DX_OpenPort( comport, br ) if ( devid != 0 ) then ret = DXLIB2.DX_Active( devid ) if ( ret == 1 ) then sleep 1 i = 0 while ( i <= 253 ) ret = DXLIB2.DX_Ping( devid, i, timeout, terr ) if ( ret == 1 ) then printf( "\n%d alive", i ) mark = "\n" else printf( "%s%d dead(%x)", mark, i, terr.unpack('S')[0] ) mark = "\r" end i += 1 end end ret = DXLIB2.DX_ClosePort( devid ) if ( ret == 0 ) then print "CLOSE ERROR\n" end end print("\nnormal end") |
SMPL1.rb dxlib2.dll |
> ruby SMPL1.rb |