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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? avr309.dpr

?? AVR的USB開發源代碼 USB-RS232轉換
?? 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;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人网页在线观看| 久久久久久久久久久久电影 | 日韩成人一区二区| 国产精品1区二区.| 欧美日韩成人一区| 国产精品久久国产精麻豆99网站| 亚洲1区2区3区4区| 成人av午夜电影| 欧美成人r级一区二区三区| 一区二区三区精品视频| 国产91精品在线观看| 欧美一级日韩一级| 亚洲综合精品自拍| av不卡在线播放| 国产午夜精品久久久久久免费视| 亚洲成a人片在线观看中文| eeuss鲁片一区二区三区| 欧美精品一区二区久久婷婷| 亚洲第一成年网| 色美美综合视频| 国产精品福利一区二区三区| 国产一区中文字幕| 欧美一区二区三区婷婷月色| 亚洲一级在线观看| 在线观看av一区| 亚洲欧美国产高清| 波多野结衣一区二区三区| 2023国产精品| 极品少妇xxxx精品少妇偷拍| 欧美日韩免费观看一区三区| 亚洲国产精品久久不卡毛片 | 国产美女av一区二区三区| 91精品国产免费| 日韩国产一二三区| 在线观看91精品国产入口| 一区二区三区四区乱视频| 色综合天天综合色综合av | 国产一区 二区| 26uuuu精品一区二区| 国产主播一区二区| 国产亚洲一区二区在线观看| 国产福利91精品| 日本一区二区电影| 色综合久久久久| 亚洲另类中文字| 欧美日韩精品一区二区| 视频在线观看91| 精品黑人一区二区三区久久| 激情综合色综合久久综合| 久久久久久久精| 99精品一区二区三区| 亚洲午夜久久久| 精品日韩欧美在线| 高清成人在线观看| 一区2区3区在线看| 日韩亚洲电影在线| 成人性生交大片| 亚洲综合激情另类小说区| 3atv一区二区三区| 国产精品正在播放| 亚洲免费观看在线视频| 欧美精品在线观看播放| 国产一区二区福利| 亚洲激情男女视频| 精品1区2区在线观看| aaa亚洲精品| 青青国产91久久久久久| 国产欧美日韩亚州综合| 欧美在线观看一区| 国产精品综合一区二区三区| 亚洲色图在线看| 欧美大片国产精品| 91在线你懂得| 国内外精品视频| 亚洲午夜精品网| 久久精品欧美日韩| 欧美三区免费完整视频在线观看| 久久国产精品72免费观看| 国产精品私人自拍| 欧美精品在欧美一区二区少妇| 国产麻豆成人精品| 偷偷要91色婷婷| 国产精品色呦呦| 丰满少妇久久久久久久| 免费视频最近日韩| 夜夜嗨av一区二区三区中文字幕| 久久免费视频色| 777午夜精品视频在线播放| 成人av在线网| 国内外精品视频| 亚洲电影第三页| ...xxx性欧美| 欧美国产亚洲另类动漫| 宅男在线国产精品| 欧美中文字幕一区二区三区亚洲| 国产91丝袜在线18| 久久精品99久久久| 亚洲成年人网站在线观看| 亚洲精品精品亚洲| 国产精品成人网| 国产精品嫩草影院av蜜臀| 久久综合久久综合久久| 欧美一级高清大全免费观看| 欧洲中文字幕精品| 97久久精品人人做人人爽50路 | 婷婷夜色潮精品综合在线| 亚洲精品免费播放| 亚洲久本草在线中文字幕| 国产亚洲美州欧州综合国| 日韩欧美久久久| 日韩欧美一二区| 日韩精品一区二区在线观看| 91精品综合久久久久久| 欧美日韩综合不卡| 欧美精品第1页| 宅男噜噜噜66一区二区66| 欧美日韩国产精选| 欧美日韩一级大片网址| 欧美吻胸吃奶大尺度电影| 在线欧美一区二区| 欧美四级电影在线观看| 欧美色图激情小说| 欧美一区二区三区在线看| 91精品综合久久久久久| 欧美大片在线观看一区二区| 精品日本一线二线三线不卡| 欧美精品一区二区三区久久久| 欧美一二三区精品| 久久综合久久综合久久综合| 久久久精品2019中文字幕之3| 国产日韩精品一区二区三区| 国产女主播视频一区二区| 中文字幕精品一区二区精品绿巨人| 国产亚洲人成网站| 亚洲日本电影在线| 午夜精彩视频在线观看不卡| 免费成人美女在线观看| 国产精品资源在线| av高清久久久| 日韩高清一区二区| 国产丝袜美腿一区二区三区| 国产suv精品一区二区三区| 国产成人精品午夜视频免费| heyzo一本久久综合| 欧美最新大片在线看| 91精品蜜臀在线一区尤物| 久久―日本道色综合久久| 久久久99精品久久| 亚洲精品五月天| 日本怡春院一区二区| 国产高清视频一区| 色综合久久88色综合天天6| 6080午夜不卡| 久久久精品国产99久久精品芒果| 综合久久久久久久| 日韩精品一卡二卡三卡四卡无卡| 国产综合色视频| 91色九色蝌蚪| 精品国产乱码久久久久久免费| 综合激情网...| 麻豆精品视频在线| 色婷婷国产精品综合在线观看| 欧美一区永久视频免费观看| 欧美高清一级片在线观看| 午夜国产精品影院在线观看| 丁香婷婷综合色啪| 69精品人人人人| 亚洲蜜臀av乱码久久精品蜜桃| 日韩1区2区日韩1区2区| av中文字幕不卡| 精品久久五月天| 亚洲国产va精品久久久不卡综合| 国产激情一区二区三区| 91精品综合久久久久久| 亚洲精品伦理在线| 成人一级片网址| 久久久综合精品| 久久精品国产亚洲一区二区三区| 99精品视频在线观看| 久久久久久久性| 免费欧美在线视频| 欧美日韩一区不卡| 中文字幕在线不卡| 国产成人8x视频一区二区 | 91美女在线看| 中文字幕精品一区二区精品绿巨人 | 亚洲一区二区三区在线播放| 粉嫩一区二区三区在线看| 精品国精品自拍自在线| 日韩激情一二三区| 欧美午夜一区二区三区 | 欧洲一区在线电影| 亚洲人成网站在线| av中文字幕亚洲| 日本一区二区三区免费乱视频| 久久精品国产网站| 日韩欧美一区二区久久婷婷| 亚洲国产成人av网| 欧美精品三级在线观看| 亚洲二区视频在线|