亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? avr309.dpr

?? Appliction => rs232測試 應(yīng)用程式 Driver => usb to rs232 驅(qū)動程式(wdm ddk) DLL => 應(yīng)用程式 Firmware =&g
?? DPR
?? 第 1 頁 / 共 3 頁
字號:
library AVR309;
{
  Author: Ing. Igor Cesko
          http://www.cesko.host.sk
          cesko@internet.sk
  Project: AVR309 application note : USB to UART converter
           www.atmel.com
}

//{$DEFINE DemoVersion}
  {$WARN UNSAFE_CODE OFF}
  {$WARN UNSAFE_TYPE OFF}
  {$WARN UNSAFE_CAST OFF}

uses
  Windows,Mmsystem,Messages;
{$R *.RES} //resource: AVRUSBicon
const
  GlobalRS232BufferHiIndexLength=100016; //length of RS232 buffer
type
  TGlobalRS232Buffer=array[0..GlobalRS232BufferHiIndexLength]of byte;
const
  DrvName:PChar='\\.\AVR309USB_0'; //name of driver IgorPlug.sys
  RS232BufferFileMappedName='IgorPlugUSBRS232FileMappedHandleName'; //name of unique memory mapped file - RS232 buffer
  RS232BufferMutexName='IgorPlugUSBRS232MutexHandleName'; //name of unique mutex receiving RS232 thread
  SerializationEventName='IgorPlugDLLEvent'; //name of unique event for serialization access to hardware
  UARTx2Mode:boolean=false;

const
  PGlobalRS232Buffer:^TGlobalRS232Buffer=nil; //pointer to RS232 buffer (unique in system - memory maped file)
  GlobalRS232BufferLength=SizeOf(TGlobalRS232Buffer); //size of RS232 buffer
  RS232BufferFileMappedHND:THandle=0;//file mapped handle of RS232 buffer
  RS232BufferWrite:integer=0;//write position in RS232 buffer
  RS232BufferRead:integer=0;//read position in RS232 buffer
  GlobalRS232BufferEnd=High(TGlobalRS232Buffer)-16;//end of write position in RS232 buffer (can be overrun up to 8 bytes)
  GlobalRS232BufferWritePos:integer=GlobalRS232BufferHiIndexLength-SizeOf(GlobalRS232BufferWritePos); //position in RS232 buffer where is located write position in RS232 buffer (for other applications to know where buffer ends)

  IsRS232PrevInst: Boolean=true; //if there is previous application with DLL using
  RS232MutexHandle: THandle=0; //handle of unique mutex - for detection if exist another application using this DLL

  DrvHnd:DWORD=INVALID_HANDLE_VALUE; //handle of driver IgorPlug.sys
  OutputDataLength=256;
var
  OutputData:array[0..OutputDataLength-1] of byte; //data to USB
const
  OutLength:integer=0; //length of data to USB

  DoGetRS232BufferTimer:integer=0; //handle of timer generating event: reading to RS232 from device FIFO in intervals
  RS232BufferTimerInterval:integer=10; //interval for reading from device FIFO into RS232 buffer
  RS232BufferThreadId:integer=0; //reading RS232 buffer thread ID
  RS232BufferThreadHND:integer=0; //reading RS232 buffer thread handle
  RS232BufferGetEvent:integer=0; //event - signal for read from device FIFO
  RS232BufferEndEvent:integer=0; //event to stop cyclic reading RS232 buffer thread
  LocalThreadRunningEvent:integer=0; //event to signal to end of local RS232 buffer thread


  SerializationEvent:THandle=0; //handle of serialization event - for serialization access to hardware
  SerializationEventTimeout:integer=20000;//20 seconds to wait to end previous device access

  HookHandle:integer=0; //hook handle: DLL is hooking message WM_QUIT to safe resouce unallocation

  {$IFDEF DemoVersion}
    DemoOK:integer=IDNO; //if there was clicked OK in DEMO version (in registered version is this IDOK)
    OKDemoValue:integer=IDOK+1; //for hackers debugging - comparing value with DemoOK
  {$ENDIF}


  //Function numbers in hardware device
  FNCNumberDoSetInfraBufferEmpty	=1	;//;restart of infra reading (if was stopped by RAM reading)
  FNCNumberDoGetInfraCode		=2	;//;transmit of receved infra code (if some code in infra buffer)
  FNCNumberDoSetDataPortDirection	=3	;//;set direction of data bits
  FNCNumberDoGetDataPortDirection	=4	;//;get direction of data bits
  FNCNumberDoSetOutDataPort		=5	;//;set data bits (if are bits as input, then set theirs pull-ups)
  FNCNumberDoGetOutDataPort		=6	;//;get data bits (if are bits as input, then get theirs pull-ups)
  FNCNumberDoGetInDataPort		=7	;//;get data bits - pin reading
  FNCNumberDoEEPROMRead			=8	;//;read EEPROM from given address
  FNCNumberDoEEPROMWrite		=9	;//;write data byte to EEPROM to given address
  FNCNumberDoRS232Send  		=10	;//;send one data byte to RS232 line
  FNCNumberDoRS232Read			=11	;//;read one data byte from serial line (only when FIFO not implemented in device)
  FNCNumberDoSetRS232Baud		=12	;//;set baud speed of serial line
  FNCNumberDoGetRS232Baud		=13     ;//;get baud speed of serial line (exact value)
  FNCNumberDoGetRS232Buffer		=14     ;//;get received bytes from FIFO RS232 buffer
  FNCNumberDoSetRS232DataBits           =15     ;//;set number of data bits of serial line
  FNCNumberDoGetRS232DataBits           =16     ;//;get number of data bits of serial line
  FNCNumberDoSetRS232Parity             =17     ;//;set parity of serial line
  FNCNumberDoGetRS232Parity             =18     ;//;get parity of serial line
  FNCNumberDoSetRS232StopBits           =19     ;//;set stopbits of serial line
  FNCNumberDoGetRS232StopBits           =20     ;//;get stopbits of serial line

  //results - answers from device
  NO_ERROR=0;
  DEVICE_NOT_PRESENT=1;
  NO_DATA_AVAILABLE=2;
  INVALID_BAUDRATE=3;
  OVERRUN_ERROR=4;
  INVALID_DATABITS=5;
  INVALID_PARITY=6;
  INVALID_STOPBITS=7;

//-------------------------------------------------------------------------------------------------------
function DoGetRS232Baud(var BaudRate:integer):integer;  stdcall export; forward;
//-------------------------------------------------------------------------------------------------------
function FNHookProc(code:Integer; wparam:Integer; lparam:Integer): Longint stdcall;
// Hook function: only when application ends then safely frees FIFO reading thread
var
  lpMsg:^TMsg;
begin
  lpMsg:=pointer(lparam);
  Result:=CallNextHookEx(HookHandle,code,wParam,lParam);
  if (lpMsg^.message=WM_QUIT) then
    begin
      if DoGetRS232BufferTimer<>0 then
        begin
          timeKillEvent(DoGetRS232BufferTimer);
          DoGetRS232BufferTimer:=0;
        end;
      SetEvent(RS232BufferEndEvent);
      WaitForSingleObject(RS232BufferThreadHND,5000);
      CloseHandle(RS232BufferThreadHND);
      RS232BufferThreadHND:=0;
    end;
end;
//-------------------------------------------------------------------------------------------------------
procedure ShowThreadErrorMessage;
//if some thread locks serialization access - display message
const
  InProgress:boolean=false;
begin
  SetEvent(SerializationEvent);
  if InProgress then Exit;
  InProgress:=true;
  MessageBox(0,'Another thread is using long time AVR309.dll','Error',MB_OK or MB_ICONERROR or MB_TASKMODAL or MB_TOPMOST);
  InProgress:=false;
end;
//-------------------------------------------------------------------------------------------------------
function OpenDriver:boolean;
//open device driver
  begin
    Result:=false;
    DrvHnd:=CreateFile(PChar(DrvName),GENERIC_WRITE or GENERIC_READ, FILE_SHARE_WRITE or FILE_SHARE_READ,
               nil,OPEN_EXISTING,0,0);
    if DrvHnd=INVALID_HANDLE_VALUE then Exit;
    Result:=true;
  end;
//-------------------------------------------------------------------------------------------------------
function CloseDriver:boolean;
//close device driver
  begin
    Result:=true;
    if DrvHnd<>INVALID_HANDLE_VALUE then CloseHandle(DrvHnd);
  end;
//-------------------------------------------------------------------------------------------------------
function SendToDriver(FunctionNumber:byte; Param1,Param2:word;
                      var OutputData:array of byte; var OutLength:integer):boolean;
//send and receive data to device through device driver
  var
    LocalInBuffer:array [0..4] of byte;
    RepeatCount:integer;
    OutLengthMax:integer;
  begin
    {$IFDEF DemoVersion}
      if abs(DemoOK)<>(Round(OKDemoValue)-1) then
        WaitForSingleObject(SerializationEvent,SerializationEventTimeout);//delay for bad cracking
    {$ENDIF}
    RepeatCount:=3;
    Result:=false;
    if not OpenDriver then
      begin
        OutLength:=0;
        Exit;
      end;
    LocalInBuffer[0]:=FunctionNumber;
    LocalInBuffer[1]:=Lo(Param1);
    LocalInBuffer[2]:=Hi(Param1);
    LocalInBuffer[3]:=Lo(Param2);
    LocalInBuffer[4]:=Hi(Param2);
    if OutLength<0 then
      OutLengthMax:=OutputDataLength
    else
      OutLengthMax:=OutLength;
    if OutLengthMax>255 then
      OutLengthMax:=255;
    try
      repeat
        Result:=DeviceIoControl(DrvHnd,$800+8,@LocalInBuffer,5,@OutputData,OutLengthMax,cardinal(OutLength),nil);
        Result:=Result and (OutLength>0);
        dec(RepeatCount);
      until (OutLength>0)or(RepeatCount<=0);
    except
      DrvHnd:=CreateFile(PChar(DrvName),GENERIC_WRITE or GENERIC_READ, FILE_SHARE_WRITE or FILE_SHARE_READ,nil,OPEN_EXISTING,0,0);
    end;
    CloseDriver;
  end;
//-------------------------------------------------------------------------------------------------------
function DoSetInfraBufferEmpty:integer;  stdcall export;
//;restart of infra reading (if was stopped by RAM reading)
  begin
    Result:=DEVICE_NOT_PRESENT;
    OutLength:=1;
    if SendToDriver(FNCNumberDoSetInfraBufferEmpty,0,0,OutputData,OutLength) then
      Result:=NO_ERROR;
  end;
//-------------------------------------------------------------------------------------------------------
function DoGetInfraCode(var TimeCodeDiagram:array of byte; var DiagramLength:integer):integer;  stdcall export;
//;transmit of receved infra code (if some code in infra buffer)
  const
    LastReadedCode:integer=-1;
    HeaderLength=3;
  var
    BytesToRead:integer;
    OutputData:array[0..200]of byte;
    LastWrittenIndex:integer;
    i,j,k:integer;
  begin
    if WaitForSingleObject(SerializationEvent,SerializationEventTimeout)=WAIT_TIMEOUT then
      begin
        ShowThreadErrorMessage;
        Result:=DEVICE_NOT_PRESENT;
        Exit;
      end;
    Result:=DEVICE_NOT_PRESENT;
    DiagramLength:=0;
    OutLength:=3;  //3 bytes is IR header length
    if not SendToDriver(FNCNumberDoGetInfraCode,0,0,OutputData,OutLength) then
      begin
        SetEvent(SerializationEvent);
        Exit;
      end;
    BytesToRead:=OutputData[0];
    if (LastReadedCode=OutputData[1])or(OutLength<=1)or(BytesToRead=0) then
      begin
        Result:=NO_ERROR;
        SetEvent(SerializationEvent);
        Exit;
      end;
    LastReadedCode:=OutputData[1];
    LastWrittenIndex:=OutputData[2];
    i:=0;
    while i<BytesToRead do
      begin
        OutLength:=BytesToRead-i;
        if not SendToDriver(FNCNumberDoGetInfraCode,i+HeaderLength,0,OutputData[i],OutLength) then
          begin
            DoSetInfraBufferEmpty;
            LastReadedCode:=-1;
            SetEvent(SerializationEvent);
            Exit;
          end;
        inc(i,OutLength);
      end;
    j:=LastWrittenIndex mod BytesToRead;
    k:=0;
    for i:=j to BytesToRead-1 do
      begin
        TimeCodeDiagram[k]:=OutputData[i];
        inc(k);
      end;
    for i:=0 to (j-1) do
      begin
        TimeCodeDiagram[k]:=OutputData[i];
        inc(k);
      end;
    DiagramLength:=BytesToRead;
    DoSetInfraBufferEmpty;
    Result:=NO_ERROR;
    SetEvent(SerializationEvent);
  end;
//-------------------------------------------------------------------------------------------------------
function DoSetDataPortDirections(DirectionByteB, DirectionByteC, DirectionByteD:byte; UsedPorts:byte):integer;  stdcall export;
//;set direction of data bits
var
  Param1,Param2:word;
  begin
    if WaitForSingleObject(SerializationEvent,SerializationEventTimeout)=WAIT_TIMEOUT then
      begin
        ShowThreadErrorMessage;
        Result:=DEVICE_NOT_PRESENT;
        Exit;
      end;
    Result:=DEVICE_NOT_PRESENT;
    Param1:=DirectionByteC;
    Param1:=(Param1 shl 8) or DirectionByteB;
    Param2:=UsedPorts;
    Param2:=(Param2 shl 8) or DirectionByteD;
    OutLength:=1;
    if SendToDriver(FNCNumberDoSetDataPortDirection,Param1,Param2,OutputData,OutLength) then
      Result:=NO_ERROR;
    SetEvent(SerializationEvent);
  end;
//-------------------------------------------------------------------------------------------------------
function DoSetDataPortDirection(DirectionByte:byte):integer;  stdcall export;
//;set direction of data bits (all ports the same)
  begin
    Result:=DoSetDataPortDirections(DirectionByte,DirectionByte,DirectionByte,$FF);
  end;
//-------------------------------------------------------------------------------------------------------
function DoGetDataPortDirections(var DataDirectionByteB, DataDirectionByteC, DataDirectionByteD:byte; var UsedPorts:byte):integer;  stdcall export;
//;get direction of data bits
  begin
    if WaitForSingleObject(SerializationEvent,SerializationEventTimeout)=WAIT_TIMEOUT then
      begin
        ShowThreadErrorMessage;
        Result:=DEVICE_NOT_PRESENT;
        Exit;
      end;
    Result:=DEVICE_NOT_PRESENT;
    OutLength:=3;
    if not SendToDriver(FNCNumberDoGetDataPortDirection,0,0,OutputData,OutLength) then
      begin
        SetEvent(SerializationEvent);
        Exit;
      end;
    UsedPorts:=0;
    if (OutLength>0)and(@DataDirectionByteB<>nil) then
      begin
        DataDirectionByteB:=OutputData[0];
        UsedPorts:=UsedPorts or 1;
      end;
    if (OutLength>1)and(@DataDirectionByteC<>nil) then
      begin
        DataDirectionByteC:=OutputData[1];
        UsedPorts:=UsedPorts or 2;
      end;
    if (OutLength>2)and(@DataDirectionByteD<>nil) then
      begin
        DataDirectionByteD:=OutputData[2];
        UsedPorts:=UsedPorts or 4;
      end;
    Result:=NO_ERROR;
    SetEvent(SerializationEvent);
  end;
//-------------------------------------------------------------------------------------------------------
function DoGetDataPortDirection(var DataDirectionByte:byte):integer;  stdcall export;
//;get direction of data bits
  var
    Dummy:byte;
  begin
    Result:=DoGetDataPortDirections(DataDirectionByte,Dummy,Dummy,Dummy);
  end;
//-------------------------------------------------------------------------------------------------------
function DoSetOutDataPorts(DataOutByteB, DataOutByteC, DataOutByteD:byte; UsedPorts:byte):integer;  stdcall export;
//;set data bits (if are bits as input, then set theirs pull-ups)
var
  Param1,Param2:word;
  begin
    if WaitForSingleObject(SerializationEvent,SerializationEventTimeout)=WAIT_TIMEOUT then
      begin
        ShowThreadErrorMessage;
        Result:=DEVICE_NOT_PRESENT;
        Exit;
      end;
    Result:=DEVICE_NOT_PRESENT;
    Param1:=DataOutByteC;
    Param1:=(Param1 shl 8) or DataOutByteB;
    Param2:=UsedPorts;
    Param2:=(Param2 shl 8) or DataOutByteD;
    OutLength:=1;

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品久久久久毛片软件| 久久九九久久九九| 亚洲美女视频在线| 91福利在线播放| 午夜日韩在线观看| 久久久久久久久久久久电影 | 91免费视频观看| 亚洲成av人片一区二区| 久久先锋影音av鲁色资源网| 91网站最新网址| 99视频精品全部免费在线| 日韩电影一区二区三区四区| 久久精品视频一区二区三区| 精品国产欧美一区二区| 94-欧美-setu| 精品一区二区三区免费观看 | 成年人国产精品| 秋霞av亚洲一区二区三| 亚洲日本va午夜在线电影| 精品国产1区二区| 欧美一级理论性理论a| 色八戒一区二区三区| 欧美综合一区二区| 不卡的av在线播放| 色诱视频网站一区| 国产乱子轮精品视频| 久久精品在线免费观看| 国产精品每日更新| 久久精品视频一区| 国产精品乱码一区二区三区软件| 亚洲色图制服诱惑 | 91精品在线观看入口| 91社区在线播放| 欧美日韩国产三级| 欧美在线三级电影| 日韩欧美在线影院| 中文字幕av不卡| 久久精品免视看| 亚洲免费视频成人| 久久成人精品无人区| 日韩国产欧美一区二区三区| 国产精品亚洲一区二区三区在线| 在线看一区二区| 精品成人私密视频| 亚洲卡通欧美制服中文| 亚洲欧美另类综合偷拍| 美腿丝袜亚洲三区| 国产一区二区三区四区在线观看| 色综合欧美在线| 久久久久久久国产精品影院| 一区二区成人在线观看| 亚洲国产一区二区视频| 午夜电影网一区| 成人午夜碰碰视频| 色琪琪一区二区三区亚洲区| 欧美成人vps| 中文久久乱码一区二区| 免费观看在线综合| 欧美日韩一区二区三区四区五区| 在线播放国产精品二区一二区四区| 欧美丝袜丝交足nylons| 欧美一区二区三区电影| 日韩免费福利电影在线观看| 欧美不卡视频一区| 天堂蜜桃一区二区三区| 国产一区二区三区免费看| 欧美日韩免费电影| 亚洲欧美日韩国产综合在线| 国产成人精品一区二| 91福利区一区二区三区| 国产精品国产三级国产aⅴ无密码| 麻豆91在线播放免费| 欧美色视频在线| 亚洲乱码国产乱码精品精小说| 国产精品中文欧美| 国产情人综合久久777777| 亚洲影院理伦片| 黄网站免费久久| 91福利在线观看| 亚洲精品中文字幕在线观看| 91丨porny丨国产| 亚洲欧洲日产国码二区| 蜜臀av一区二区三区| 欧美精品免费视频| 久久激五月天综合精品| 欧美精品一区二区三区蜜臀| 久久精品99国产精品日本| 欧美v国产在线一区二区三区| 美女网站色91| 久久久久久亚洲综合影院红桃| 国产一区二区三区免费看| 中文字幕国产一区| 在线观看一区日韩| 日韩在线卡一卡二| 久久新电视剧免费观看| 成人动漫av在线| 一区二区免费在线| 日韩欧美一级二级三级久久久| 久久99久久久欧美国产| 国产精品福利一区二区三区| 色狠狠色噜噜噜综合网| 日本不卡一二三| 欧美国产激情二区三区| 日本大香伊一区二区三区| 性感美女极品91精品| 精品国产乱码久久久久久老虎| 国产盗摄视频一区二区三区| 亚洲视频综合在线| 欧美一级日韩免费不卡| 国产电影一区二区三区| 亚洲图片自拍偷拍| 久久精品夜色噜噜亚洲a∨| 91老司机福利 在线| 久久国产婷婷国产香蕉| 国产精品―色哟哟| 91精品国产色综合久久不卡蜜臀 | 国产欧美日韩亚州综合| 色欧美88888久久久久久影院| 日本伊人午夜精品| 日韩美女视频19| 精品成人一区二区三区| 色综合久久66| 国产suv精品一区二区883| 久久伊99综合婷婷久久伊| a亚洲天堂av| 久久99国产精品久久| 亚洲精品久久久久久国产精华液 | 国产一区日韩二区欧美三区| 椎名由奈av一区二区三区| 26uuu国产日韩综合| 欧美巨大另类极品videosbest | 久久免费的精品国产v∧| 在线视频欧美精品| 国产**成人网毛片九色| 午夜电影网亚洲视频| 亚洲男人天堂av| 日本一区二区三区国色天香| 欧美福利视频一区| 91久久国产最好的精华液| 国产成人福利片| 国产一区二区三区免费播放| 三级在线观看一区二区| 成人欧美一区二区三区| 久久美女艺术照精彩视频福利播放| 欧美日韩高清在线| 欧美性受xxxx| 在线观看视频一区二区 | 亚洲男同1069视频| 亚洲视频综合在线| 亚洲图片欧美激情| 国产精品成人在线观看| 久久影院午夜论| 久久久久国产精品人| 久久婷婷成人综合色| 精品国产一区二区三区久久久蜜月 | 久久99精品久久久| 美国十次了思思久久精品导航| 天天综合天天综合色| 午夜精品爽啪视频| 亚洲福利视频三区| 日韩av在线免费观看不卡| 日韩电影免费在线| 美女一区二区久久| 国产在线精品一区二区| 激情欧美一区二区| 成人午夜在线播放| 色婷婷精品久久二区二区蜜臀av | 日韩激情视频网站| 日韩和欧美一区二区三区| 丝袜脚交一区二区| 美女性感视频久久| 国产老肥熟一区二区三区| 成人综合在线视频| 97国产一区二区| 欧美日韩精品一区二区三区蜜桃 | 国产精品1区2区3区| 成人久久久精品乱码一区二区三区| 成人妖精视频yjsp地址| av在线不卡免费看| 欧美日韩一区中文字幕| 欧美一区二区三区性视频| 精品国产乱码久久久久久夜甘婷婷 | 欧美色国产精品| 欧美v日韩v国产v| 亚洲欧洲日韩在线| 丝袜美腿亚洲综合| 国产在线精品一区二区夜色| www.日韩大片| 91麻豆精品国产91久久久使用方法| 日韩一级精品视频在线观看| 国产精品网站一区| 亚洲香蕉伊在人在线观| 狠狠色丁香久久婷婷综合_中| 99在线视频精品| 欧美一级免费大片| 亚洲人成精品久久久久久| 日韩电影在线观看一区| 99久久国产综合色|国产精品| 在线不卡a资源高清| 亚洲手机成人高清视频|