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

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

?? avr309.dpr

?? AVR的USB開發(fā)源代碼 USB-RS232轉(zhuǎn)換
?? 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一区二区三区免费野_久草精品视频
欧美一区二区私人影院日本| 一本久久a久久精品亚洲| 成人免费视频在线观看| 日韩一区二区三区四区五区六区| av成人老司机| 成人动漫在线一区| 国产不卡在线一区| 久久精品免费观看| 精品无码三级在线观看视频| 久久成人羞羞网站| 黄色日韩网站视频| 成人av网站大全| 91色视频在线| 在线观看视频欧美| 日韩一区二区中文字幕| 久久综合久久久久88| 国产欧美日韩视频一区二区| 国产精品久久久久婷婷| 夜夜夜精品看看| 美女视频黄 久久| 国产精一区二区三区| 成人性生交大片免费看中文| 色综合天天天天做夜夜夜夜做| 91福利区一区二区三区| 欧美大尺度电影在线| 亚洲国产高清在线| 亚洲国产乱码最新视频| 韩国v欧美v日本v亚洲v| 成人激情图片网| 欧美猛男超大videosgay| 欧美成人艳星乳罩| 18成人在线观看| 日韩av二区在线播放| 国v精品久久久网| 在线视频国产一区| 久久综合久久综合九色| 亚洲视频免费看| 日韩影院免费视频| 91在线精品一区二区三区| 制服丝袜亚洲精品中文字幕| 中文字幕电影一区| 亚洲国产精品视频| 成人av电影观看| 欧美大度的电影原声| 国产精品第13页| 另类小说一区二区三区| 色综合久久久久久久久久久| 日韩女优av电影| 亚洲一级二级三级| 成人高清伦理免费影院在线观看| 制服丝袜在线91| 亚洲美女一区二区三区| 国产一区91精品张津瑜| 欧美午夜一区二区| 国产精品欧美极品| 国产精品456| 日韩一区二区三免费高清| 亚洲免费av观看| 91小视频在线免费看| 国产视频一区不卡| 狠狠色综合色综合网络| 51精品久久久久久久蜜臀| 亚洲一区影音先锋| 日本韩国精品在线| 亚洲男女一区二区三区| 99精品视频中文字幕| 国产精品久久久久久久第一福利 | 狠狠色伊人亚洲综合成人| 在线电影院国产精品| 一区二区三区美女| 在线免费观看日本一区| 国产精品久久久久久久午夜片| 国产自产视频一区二区三区| 日韩午夜激情视频| 裸体一区二区三区| 日韩一区二区三区免费观看| 奇米777欧美一区二区| 91精品福利在线一区二区三区 | 日本 国产 欧美色综合| 欧美一区二区三区影视| 日本伊人色综合网| 7777精品伊人久久久大香线蕉经典版下载 | 91在线视频免费91| 国产精品久久久一本精品 | 欧美激情一区二区三区四区| 国产一区二区女| 久久精品夜色噜噜亚洲aⅴ| 国精产品一区一区三区mba桃花| 久久久综合九色合综国产精品| 久久精品噜噜噜成人88aⅴ| 精品播放一区二区| 成人国产精品免费| 亚洲一区二区三区自拍| 91精品欧美一区二区三区综合在| 日本va欧美va瓶| 国产精品三级av| 欧美日韩精品一区二区天天拍小说| 日韩中文字幕一区二区三区| 日韩欧美国产麻豆| 国产一区二区三区四区五区入口| 国产精品成人一区二区艾草| 99久久久久久99| 日本不卡高清视频| 2019国产精品| 成人激情免费网站| 丝袜诱惑制服诱惑色一区在线观看| 日韩一级二级三级| 国产成人av一区| 一区二区三区国产精品| 欧美成人bangbros| 成人高清视频在线观看| 亚洲国产成人91porn| 2021国产精品久久精品| 日本乱码高清不卡字幕| 国产精品综合在线视频| 亚洲一线二线三线久久久| 日韩一区二区影院| 欧美福利视频导航| 成人黄色免费短视频| 蜜桃传媒麻豆第一区在线观看| 亚洲欧美一区二区三区国产精品| 欧美一级片在线看| 色婷婷激情一区二区三区| 国内精品伊人久久久久av影院| 亚洲伦理在线免费看| 精品国产乱码久久久久久夜甘婷婷 | 久久婷婷色综合| 欧美视频一区二区在线观看| 高清不卡在线观看av| 久久av老司机精品网站导航| 亚洲高清免费一级二级三级| 国产精品国产三级国产普通话蜜臀| 欧美一区二区在线视频| 欧美图片一区二区三区| 99re这里都是精品| 成人激情午夜影院| 免费人成精品欧美精品| 亚洲国产美国国产综合一区二区| 久久色在线观看| 精品少妇一区二区| 欧美一区二区三区人| 欧美日本国产一区| 欧美性xxxxxx少妇| 欧美视频一区在线观看| 欧美中文一区二区三区| 欧美在线视频日韩| 色悠悠亚洲一区二区| 91在线porny国产在线看| 国产jizzjizz一区二区| 国产精品一区二区在线播放 | 国产在线播放一区三区四| 天堂久久久久va久久久久| 亚洲高清不卡在线观看| 亚洲午夜一二三区视频| 日韩中文字幕1| 免费观看成人鲁鲁鲁鲁鲁视频| 日韩成人精品在线| 久久99久久99精品免视看婷婷| 精品中文字幕一区二区| 国产乱码精品1区2区3区| 国产精品99精品久久免费| 成人一区二区三区| 色婷婷综合久久| 欧美精品视频www在线观看| 日韩一区二区在线免费观看| 久久蜜桃香蕉精品一区二区三区| 国产午夜亚洲精品理论片色戒 | 欧美性受极品xxxx喷水| 欧美三级蜜桃2在线观看| 777xxx欧美| 久久久久国产一区二区三区四区| 国产精品区一区二区三| 一区二区三区在线免费| 日韩精品成人一区二区三区| 国内不卡的二区三区中文字幕| 国产另类ts人妖一区二区| 波多野结衣欧美| 欧美日韩国产另类不卡| 久久久久久久综合狠狠综合| 亚洲乱码国产乱码精品精的特点| 天堂久久久久va久久久久| 国产mv日韩mv欧美| 欧美日韩专区在线| 国产日韩欧美综合一区| 亚洲国产欧美一区二区三区丁香婷| 激情成人综合网| 色呦呦一区二区三区| 欧美α欧美αv大片| 亚洲精选视频在线| 韩日av一区二区| 在线看国产一区二区| 久久久久久99精品| 日韩精品免费视频人成| www.亚洲在线| 97久久精品人人澡人人爽| 日韩欧美一区二区免费| 免费久久99精品国产| 97精品国产露脸对白| 蜜桃av一区二区三区电影| 91色porny|