pbi pour périphérique IrDA

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Ollivier
Messages : 4190
Inscription : ven. 29/juin/2007 17:50
Localisation : Encore ?
Contact :

pbi pour périphérique IrDA

Message par Ollivier »

Code pour utiliser les périphériques IrDA.

Source : IrDA pbi
Auteur du code : HeXOR

Code : Merci à Taz pour le code plus bas

Explications :
HeXor a écrit :This is an include to use IrDA devices (I only tested serial Irda adapters).
Supported os are windows and linux, macos shouldn't be a big deal either, this is just a little socket-action.

Remark:
It is only one connection at once allowed, but this should be enough anyway.
I was too lazy to add multi connections support.
HeXor traduit a écrit :Voici un fichier Include pour utiliser les périphériques IrDA (infrarouges) (je n'ai testé que des adaptateurs séries)
Les systèmes d'exploitations supportés sont Windows et Linux, MacOX (OSX) ne devrait pas poser trop de problème, c'est juste une petite "socket-action".

Remarque :
Ce la ne permet que les connections une par une, mais cela devrait suffire dans la majeure partie des cas.
Je suis trop fainéant pour ajouter le support multi-connections
Dernière modification par Ollivier le dim. 16/août/2015 1:33, modifié 1 fois.
Avatar de l’utilisateur
SPH
Messages : 4726
Inscription : mer. 09/nov./2005 9:53

Re: pbi pour périphérique IrDA

Message par SPH »

Bourré d'instruction qui n'existe pas...
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
Avatar de l’utilisateur
TazNormand
Messages : 1294
Inscription : ven. 27/oct./2006 12:19
Localisation : Calvados (14)

Re: pbi pour périphérique IrDA

Message par TazNormand »

Encore un problème de copier-coller...

Code : Tout sélectionner

;*******************************************
;*
;* Filename: IrDA.pbi
;* Version: V1.0.0
;* Date: 31.07.2015
;* Author: HeX0R
;* http://hex0rs.coderbu.de
;*
;* License: BEER-WARE
;* Thomas 'HeX0R' Milz wrote this file. As long
;As you retain this notice you
;* can do whatever you want with this stuff. If
;we meet some day, And you think
;* this stuff is worth it, you can buy me a beer
;in Return.
;*
;HeX0R@coderbu.de
;*
;* OS: [x] Windows
;* [x] Linux
;* [ ] MacOS (someone needs to add the correct
;api calls And constants)
;*
;* Description: This is an include to use IrDA adapters
;* I only needed it for serial IrDA adapters,
;don't know if others will work also
;*
;* useful links: [win] https://msdn.microsoft.com/de-de/
;library/windows/desktop/ms738544%28v=vs.85%29.aspx
;* [linux] http://lxr.free-electrons.com/source/
;include/uapi/linux/irda.h#L124
;*
;*
;* Usage
;* Please have a look at the comments and at the example at the
;bottom of the code.
;*
;*
;*******************************************
DeclareModule IrDA
Declare Init()
Declare ExamineIrdaDevices()
Declare NextIrdaDevice()
Declare.s GetIrdaDeviceName()
Declare GetIrdaDeviceID()
Declare FinishExamineIrda()
Declare Connect(DeviceID)
Declare Disconnect()
Declare SendData(*Buffer, BufferLen)
Declare ReceiveData(*Buffer, BufferLen)
Declare IsDataAvailable()
Declare GetSockID()
Declare GetLastError()
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
;Error Handling
#ERROR_NONE = #ERROR_SUCCESS
#ERROR_NO_INIT_NETWORK = #WSANOTINITIALISED
#ERROR_NETWORK_DOWN = #WSAENETDOWN
#ERROR_NO_IRDA_SUPPORT = #WSAEAFNOSUPPORT
#ERROR_NO_MORE_DEVICES = #WSAEMFILE
#ERROR_ADDRESS_IN_USE = #WSAEADDRINUSE
#ERROR_NO_MEMORY = #WSAENOBUFS
#ERROR_PROTOCOL_NOT_SUPPORTED = #WSAEPROTONOSUPPORT
#ERROR_PROTOCOLTYPE_WRONG = #WSAEPROTOTYPE
#ERROR_NOT_YET_CONNECTED = 1
#ERROR_SOCKET_ALREADY_CONNECTED = #WSAEISCONN
#ERROR_NO_EXAMINE_IRDA_DEVICES = 2
#ERROR_TIMED_OUT = #WSAETIMEDOUT
#ERROR_INVALID_SOCKET = #INVALID_SOCKET
CompilerCase #PB_OS_Linux
;Error Handling
;Errors
#EAGAIN = 11
#EACCES = 13
#EAFNOSUPPORT = 97
#EINVAL = 22
#EMFILE = 24
#ENFILE = 23
#ENOBUFS = 105
#ENOMEM = 12
#EPROTONOSUPPORT = 93
#ERROR_NONE = 0
#ERROR_NO_INIT_NETWORK = -4
#ERROR_NETWORK_DOWN = 0
#ERROR_NO_IRDA_SUPPORT = #EAGAIN
#ERROR_NO_MORE_DEVICES = -2
#ERROR_ADDRESS_IN_USE = 0
#ERROR_NO_MEMORY = #ENOBUFS
#ERROR_PROTOCOL_NOT_SUPPORTED = #EINVAL
#ERROR_PROTOCOLTYPE_WRONG = #EACCES
#ERROR_NOT_YET_CONNECTED = -5
#ERROR_SOCKET_ALREADY_CONNECTED = 0
#ERROR_NO_EXAMINE_IRDA_DEVICES = -3
#ERROR_TIMED_OUT = 0
#ERROR_INVALID_SOCKET = -1
CompilerEndSelect
EndDeclareModule
Module IrDa
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
Procedure __GetLastError()
ProcedureReturn WSAGetLastError_()
EndProcedure
Structure SOCKADDR_IRDA
irdaAddressFamily.w
irdaDeviceID.l
irdaServiceName.b[25]
EndStructure
Structure IRDA_DEVICE_INFO
irdaDeviceID.l
irdaDeviceName.b[22]
Reserved.b[2]
EndStructure
Structure DEVICELIST
numDevice.l
Device.IRDA_DEVICE_INFO[0]
EndStructure
#AF_IRDA = 26
#PF_IRDA = #AF_IRDA
#SOL_IRLMP = $00FF;
#IRLMP_ENUMDEVICES = $00000010;
#IRLMP_IAS_SET = $00000011;
#IRLMP_IAS_QUERY = $00000012;
#IRLMP_SEND_PDU_LEN = $00000013;
#IRLMP_EXCLUSIVE_MODE = $00000014;
#IRLMP_IRLPT_MODE = $00000015;
#IRLMP_9WIRE_MODE = $00000016;
#IRLMP_TINYTP_MODE = $00000017;
#IRLMP_PARAMETERS = $00000018;
#IRLMP_DISCOVERY_MODE = $00000019;
#IAS_ATTRIB_NO_CLASS = $00000010;
#IAS_ATTRIB_NO_ATTRIB = $00000000;
#IAS_ATTRIB_INT = $00000001;
#IAS_ATTRIB_OCTETSEQ = $00000002;
#IAS_ATTRIB_STR = $00000003;
#IAS_MAX_USER_STRING = 256;
#IAS_MAX_OCTET_STRING = 1024;
#IAS_MAX_CLASSNAME = 64;
#IAS_MAX_ATTRIBNAME = 256;
CompilerCase #PB_OS_Linux
ImportC ""
errno_location() As "__errno_location"
EndImport
Procedure __GetLastError()
ProcedureReturn PeekL(errno_location())
EndProcedure
#AF_IRDA = 23
#FIONREAD = $541B
#SOL_IRLMP = 266
#SOL_IRDA = 266
#IRLMP_ENUMDEVICES = 1
#SOCK_STREAM = 1
Structure SOCKADDR_IRDA
irdaAddressFamily.w
sir_lsap_sel.b
irdaDeviceID.l
irdaServiceName.b[25]
EndStructure
Structure IRDA_DEVICE_INFO
saddr.l
irdaDeviceID.l
irdaDeviceName.b[22]
charset.b
hints.b[2]
EndStructure
Structure DEVICELIST
numDevice.l
Device.IRDA_DEVICE_INFO[0]
EndStructure
CompilerEndSelect
InitNetwork()
EnableExplicit
Global DestSockAddr.SOCKADDR_IRDA
Global *pDevList.DEVICELIST
Global Socket, DeviceNum, LastError
Procedure Init()
;Always use Init first and also check the result
;After a Disconnect() you need to call Init() again before
;you can use Connect()!!
LastError = #ERROR_NONE
DestSockAddr\irdaAddressFamily = #AF_IRDA
DestSockAddr\irdaDeviceID = 0
PokeS(@DestSockAddr\irdaServiceName[0], "SampleIrDAService",
-1, #PB_Ascii)
Socket = SOCKET_(#AF_IRDA, #SOCK_STREAM, 0)
If Socket = #ERROR_INVALID_SOCKET
Socket = 0
LastError = __GetLastError()
ProcedureReturn #False
EndIf
ProcedureReturn Socket
EndProcedure
Procedure ExamineIrdaDevices()
;Start examination of Irda Devices
Protected pDevListLen
LastError = #ERROR_NONE
If Socket = 0
LastError = #ERROR_NO_INIT_NETWORK
ProcedureReturn #False
EndIf
*pDevList = AllocateMemory(4096)
*pDevList\numDevice = 0
pDevListLen = MemorySize(*pDevList)
If getsockopt_(Socket, #SOL_IRLMP, #IRLMP_ENUMDEVICES,
*pDevList, @pDevListLen) = #ERROR_INVALID_SOCKET
LastError = __GetLastError()
ProcedureReturn #False
EndIf
If *pDevList\numDevice = 0
LastError = #ERROR_NO_MORE_DEVICES
Debug "No IRDA devices were discovered or cached"
ProcedureReturn #False
EndIf
DeviceNum = 0
ProcedureReturn #True
EndProcedure
Procedure NextIrdaDevice()
;Lets examine the next Irda device
LastError = #ERROR_NONE
If Socket = 0
LastError = #ERROR_NO_INIT_NETWORK
ProcedureReturn #False
ElseIf *pDevList = 0
LastError = #ERROR_NO_EXAMINE_IRDA_DEVICES
ProcedureReturn #False
ElseIf *pDevList\numDevice = 0
Lasterror = #ERROR_NO_MORE_DEVICES
ProcedureReturn #False
EndIf
DeviceNum + 1
If DeviceNum > *pDevList\numDevice
Lasterror = #ERROR_NO_MORE_DEVICES
ProcedureReturn #False
EndIf
ProcedureReturn #True
EndProcedure
Procedure.s GetIrdaDeviceName()
;this is th current DeviceName
LastError = #ERROR_NONE
If Socket = 0
LastError = #ERROR_NO_INIT_NETWORK
ProcedureReturn ""
ElseIf *pDevList = 0
LastError = #ERROR_NO_EXAMINE_IRDA_DEVICES
ProcedureReturn ""
ElseIf *pDevList\numDevice < DeviceNum
Lasterror = #ERROR_NO_MORE_DEVICES
ProcedureReturn ""
EndIf
ProcedureReturn PeekS(@*pDevList\Device[DeviceNum -1]\irdaDeviceName[0], -1, #PB_Ascii)
EndProcedure
Procedure GetIrdaDeviceID()
;this is the current examined DeviceID
LastError = #ERROR_NONE
If Socket = 0
LastError = #ERROR_NO_INIT_NETWORK
ProcedureReturn #False
ElseIf *pDevList = 0
LastError = #ERROR_NO_EXAMINE_IRDA_DEVICES
ProcedureReturn #False
ElseIf *pDevList\numDevice < DeviceNum
Lasterror = #ERROR_NO_MORE_DEVICES
ProcedureReturn #False
EndIf
ProcedureReturn *pDevList\Device[DeviceNum - 1]\irdaDeviceID
EndProcedure
Procedure FinishExamineIrda()
;Finish examination previously started with
ExamineIrdaDevices()
LastError = #ERROR_NONE
If Socket = 0
LastError = #ERROR_NO_INIT_NETWORK
ProcedureReturn #False
EndIf
If *pDevList
FreeMemory(*pDevList)
*pDevList = 0
EndIf
DeviceNum = 0
EndProcedure
Procedure Connect(DeviceID)
;Connect to the IrDA Decide #DeviceID
;You can get the Device ID with the examine procedures:
;ExamineDevices(), NextIrdaDevice(), GetIrdaDeviceID(),GetIrdaDeviceName(), FinishExamineIrda()
LastError = #ERROR_NONE
If Socket = 0
LastError = #ERROR_NO_INIT_NETWORK
ProcedureReturn #False
ElseIf DestSockAddr\irdaDeviceID <> 0
LastError = #ERROR_SOCKET_ALREADY_CONNECTED
ProcedureReturn #False
EndIf
DestSockAddr\irdaDeviceID = DeviceID
If connect_(Socket, @DestSockAddr, SizeOf(SOCKADDR_IRDA)) =#ERROR_INVALID_SOCKET
DestSockAddr\irdaDeviceID = 0
LastError = __GetLastError()
ProcedureReturn #False
EndIf
ProcedureReturn #True
EndProcedure
Procedure Disconnect()
;IF YOU WANT TO REOPEN A IRDA SOCKET, RECALL INIT()!!
;A SIMPLE CONNECT() WILL NOT BE ENOUGH!
LastError = #ERROR_NONE
If Socket = 0
LastError = #ERROR_NO_INIT_NETWORK
Else
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
If closesocket_(Socket) = #ERROR_INVALID_SOCKET
LastError = __GetLastError()
EndIf
CompilerCase #PB_OS_Linux
If close_(Socket) = #ERROR_INVALID_SOCKET
LastError = __GetLastError()
EndIf
CompilerEndSelect
EndIf
Socket = 0
DestSockAddr\irdaDeviceID = 0
ProcedureReturn #True
EndProcedure
Procedure SendData(*Buffer, BufferLen)
;send data in *Buffer via IrDA
Protected Length
LastError = #ERROR_NONE
If Socket = 0
LastError = #ERROR_NO_INIT_NETWORK
ProcedureReturn #False
ElseIf DestSockAddr\irdaDeviceID = 0
LastError = #ERROR_NOT_YET_CONNECTED
ProcedureReturn #False
EndIf
Length = send_(Socket, *Buffer, BufferLen, 0)
If Length = #ERROR_INVALID_SOCKET
LastError = __GetLastError()
EndIf
ProcedureReturn Length
EndProcedure
Procedure IsDataAvailable()
;Checks if data is available and will then return the amount
;of Data waiting.
;similar to AvailableSerialPortInput
Protected Length
If Socket = 0
LastError = #ERROR_NO_INIT_NETWORK
ProcedureReturn -1
ElseIf DestSockAddr\irdaDeviceID = 0
LastError = #ERROR_NOT_YET_CONNECTED
ProcedureReturn -1
EndIf
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
ioctlsocket_(Socket, #FIONREAD, @Length)
CompilerCase #PB_OS_Linux
ioctl_(Socket, #FIONREAD, @Length)
CompilerEndSelect
ProcedureReturn Length
EndProcedure
Procedure ReceiveData(*Buffer, BufferLen)
;Receive data from the IrDA into *Buffer
;Will return the length it has been received.
Protected Length
LastError = #ERROR_NONE
If Socket = 0
LastError = #ERROR_NO_INIT_NETWORK
ProcedureReturn #False
ElseIf DestSockAddr\irdaDeviceID = 0
LastError = #ERROR_NOT_YET_CONNECTED
ProcedureReturn #False
EndIf
Length = recv_(Socket, *Buffer, BufferLen, 0)
If Length = #ERROR_INVALID_SOCKET
LastError = __GetLastError()
EndIf
ProcedureReturn Length
EndProcedure
Procedure GetSockID()
;Get the os handle of our socket
If Socket = 0
LastError = #ERROR_NO_INIT_NETWORK
ProcedureReturn #False
EndIf
ProcedureReturn Socket
EndProcedure
Procedure GetLastError()
ProcedureReturn LastError
EndProcedure
EndModule
;Example Code
CompilerIf #PB_Compiler_IsMainFile
Procedure.s ParseErrorMessages()
Protected Error, Result.s
Select IrDA::GetLastError()
Case IRDA::#ERROR_NONE
Result = "There were no error!"
Case IRDA::#ERROR_NO_INIT_NETWORK
Result = "It seems you have network problems ordidn't call IRDA::Init()!"
Case IRDA::#ERROR_NETWORK_DOWN
Result = "Network down!"
Case IRDA::#ERROR_NO_IRDA_SUPPORT
Result = "Check that the local computer has an infrared device And a device driver is installed!"
Case IRDA::#ERROR_NO_MORE_DEVICES
Result = "No (more) IrDA deviced found"
Case IRDA::#ERROR_ADDRESS_IN_USE
Result = "The Socket seems to be in use!"
Case IRDA::#ERROR_NO_MEMORY
Result = "Memory problems!"
Case IRDA::#ERROR_PROTOCOL_NOT_SUPPORTED
Result = "The protocol is not supported?!"
Case IRDA::#ERROR_PROTOCOLTYPE_WRONG
Result = "Wrong protocol type!"
Case IRDA::#ERROR_NOT_YET_CONNECTED
Result = "The socket is not connected!"
Case IRDA::#ERROR_SOCKET_ALREADY_CONNECTED
Result = "This socket is already connected!"
Case IRDA::#ERROR_NO_EXAMINE_IRDA_DEVICES
Result = "You didn't call IRDA::ExamineIrdaDevices() first!"
Case IRDA::#ERROR_TIMED_OUT
Result = "Request timed out!"
EndSelect
ProcedureReturn Result
EndProcedure
Procedure main()
Protected i
If IrDA::Init() = #False
Debug "Init failed!"
Debug ParseErrorMessages()
ProcedureReturn
EndIf
If IrDa::ExamineIrdaDevices()
While IrDA::NextIrdaDevice()
Debug IrDA::GetIrdaDeviceName()
Debug IrDA::GetIrdaDeviceID()
i = IrDA::GetIrdaDeviceID() ;<- keep the first device in mind
Wend
IrDA::FinishExamineIrda()
If IrDA::Connect(i)
Debug "ok"
Debug IrDA::Disconnect()
Else
Debug "Connection failed!"
Debug ParseErrorMessages()
EndIf
Else
Debug "Examination failed!"
Debug ParseErrorMessages()
EndIf
EndProcedure
main()
CompilerEndIf 
Image
Image
Avatar de l’utilisateur
Ar-S
Messages : 9478
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: pbi pour périphérique IrDA

Message par Ar-S »

Le même avec l'identation (Ctrl+a puis Ctrl +i dans l'ide)
C'est plus lisible.

Code : Tout sélectionner

;*******************************************
;*
;* Filename: IrDA.pbi
;* Version: V1.0.0
;* Date: 31.07.2015
;* Author: HeX0R
;* http://hex0rs.coderbu.de
;*
;* License: BEER-WARE
;* Thomas 'HeX0R' Milz wrote this file. As long
;As you retain this notice you
;* can do whatever you want with this stuff. If
;we meet some day, And you think
;* this stuff is worth it, you can buy me a beer
;in Return.
;*
;HeX0R@coderbu.de
;*
;* OS: [x] Windows
;* [x] Linux
;* [ ] MacOS (someone needs to add the correct
;api calls And constants)
;*
;* Description: This is an include to use IrDA adapters
;* I only needed it for serial IrDA adapters,
;don't know if others will work also
;*
;* useful links: [win] https://msdn.microsoft.com/de-de/
;library/windows/desktop/ms738544%28v=vs.85%29.aspx
;* [linux] http://lxr.free-electrons.com/source/
;include/uapi/linux/irda.h#L124
;*
;*
;* Usage
;* Please have a look at the comments and at the example at the
;bottom of the code.
;*
;*
;*******************************************
DeclareModule IrDA
  Declare Init()
  Declare ExamineIrdaDevices()
  Declare NextIrdaDevice()
  Declare.s GetIrdaDeviceName()
  Declare GetIrdaDeviceID()
  Declare FinishExamineIrda()
  Declare Connect(DeviceID)
  Declare Disconnect()
  Declare SendData(*Buffer, BufferLen)
  Declare ReceiveData(*Buffer, BufferLen)
  Declare IsDataAvailable()
  Declare GetSockID()
  Declare GetLastError()
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      ;Error Handling
      #ERROR_NONE = #ERROR_SUCCESS
      #ERROR_NO_INIT_NETWORK = #WSANOTINITIALISED
      #ERROR_NETWORK_DOWN = #WSAENETDOWN
      #ERROR_NO_IRDA_SUPPORT = #WSAEAFNOSUPPORT
      #ERROR_NO_MORE_DEVICES = #WSAEMFILE
      #ERROR_ADDRESS_IN_USE = #WSAEADDRINUSE
      #ERROR_NO_MEMORY = #WSAENOBUFS
      #ERROR_PROTOCOL_NOT_SUPPORTED = #WSAEPROTONOSUPPORT
      #ERROR_PROTOCOLTYPE_WRONG = #WSAEPROTOTYPE
      #ERROR_NOT_YET_CONNECTED = 1
      #ERROR_SOCKET_ALREADY_CONNECTED = #WSAEISCONN
      #ERROR_NO_EXAMINE_IRDA_DEVICES = 2
      #ERROR_TIMED_OUT = #WSAETIMEDOUT
      #ERROR_INVALID_SOCKET = #INVALID_SOCKET
    CompilerCase #PB_OS_Linux
      ;Error Handling
      ;Errors
      #EAGAIN = 11
      #EACCES = 13
      #EAFNOSUPPORT = 97
      #EINVAL = 22
      #EMFILE = 24
      #ENFILE = 23
      #ENOBUFS = 105
      #ENOMEM = 12
      #EPROTONOSUPPORT = 93
      #ERROR_NONE = 0
      #ERROR_NO_INIT_NETWORK = -4
      #ERROR_NETWORK_DOWN = 0
      #ERROR_NO_IRDA_SUPPORT = #EAGAIN
      #ERROR_NO_MORE_DEVICES = -2
      #ERROR_ADDRESS_IN_USE = 0
      #ERROR_NO_MEMORY = #ENOBUFS
      #ERROR_PROTOCOL_NOT_SUPPORTED = #EINVAL
      #ERROR_PROTOCOLTYPE_WRONG = #EACCES
      #ERROR_NOT_YET_CONNECTED = -5
      #ERROR_SOCKET_ALREADY_CONNECTED = 0
      #ERROR_NO_EXAMINE_IRDA_DEVICES = -3
      #ERROR_TIMED_OUT = 0
      #ERROR_INVALID_SOCKET = -1
  CompilerEndSelect
EndDeclareModule
Module IrDa
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      Procedure __GetLastError()
        ProcedureReturn WSAGetLastError_()
      EndProcedure
      Structure SOCKADDR_IRDA
        irdaAddressFamily.w
        irdaDeviceID.l
        irdaServiceName.b[25]
      EndStructure
      Structure IRDA_DEVICE_INFO
        irdaDeviceID.l
        irdaDeviceName.b[22]
        Reserved.b[2]
      EndStructure
      Structure DEVICELIST
        numDevice.l
        Device.IRDA_DEVICE_INFO[0]
      EndStructure
      #AF_IRDA = 26
      #PF_IRDA = #AF_IRDA
      #SOL_IRLMP = $00FF;
      #IRLMP_ENUMDEVICES = $00000010;
      #IRLMP_IAS_SET = $00000011    ;
      #IRLMP_IAS_QUERY = $00000012  ;
      #IRLMP_SEND_PDU_LEN = $00000013;
      #IRLMP_EXCLUSIVE_MODE = $00000014;
      #IRLMP_IRLPT_MODE = $00000015    ;
      #IRLMP_9WIRE_MODE = $00000016    ;
      #IRLMP_TINYTP_MODE = $00000017   ;
      #IRLMP_PARAMETERS = $00000018    ;
      #IRLMP_DISCOVERY_MODE = $00000019;
      #IAS_ATTRIB_NO_CLASS = $00000010 ;
      #IAS_ATTRIB_NO_ATTRIB = $00000000;
      #IAS_ATTRIB_INT = $00000001      ;
      #IAS_ATTRIB_OCTETSEQ = $00000002 ;
      #IAS_ATTRIB_STR = $00000003      ;
      #IAS_MAX_USER_STRING = 256       ;
      #IAS_MAX_OCTET_STRING = 1024     ;
      #IAS_MAX_CLASSNAME = 64          ;
      #IAS_MAX_ATTRIBNAME = 256        ;
    CompilerCase #PB_OS_Linux
      ImportC ""
        errno_location() As "__errno_location"
      EndImport
      Procedure __GetLastError()
        ProcedureReturn PeekL(errno_location())
      EndProcedure
      #AF_IRDA = 23
      #FIONREAD = $541B
      #SOL_IRLMP = 266
      #SOL_IRDA = 266
      #IRLMP_ENUMDEVICES = 1
      #SOCK_STREAM = 1
      Structure SOCKADDR_IRDA
        irdaAddressFamily.w
        sir_lsap_sel.b
        irdaDeviceID.l
        irdaServiceName.b[25]
      EndStructure
      Structure IRDA_DEVICE_INFO
        saddr.l
        irdaDeviceID.l
        irdaDeviceName.b[22]
        charset.b
        hints.b[2]
      EndStructure
      Structure DEVICELIST
        numDevice.l
        Device.IRDA_DEVICE_INFO[0]
      EndStructure
  CompilerEndSelect
  InitNetwork()
  EnableExplicit
  Global DestSockAddr.SOCKADDR_IRDA
  Global *pDevList.DEVICELIST
  Global Socket, DeviceNum, LastError
  Procedure Init()
    ;Always use Init first and also check the result
    ;After a Disconnect() you need to call Init() again before
    ;you can use Connect()!!
    LastError = #ERROR_NONE
    DestSockAddr\irdaAddressFamily = #AF_IRDA
    DestSockAddr\irdaDeviceID = 0
    PokeS(@DestSockAddr\irdaServiceName[0], "SampleIrDAService",
          -1, #PB_Ascii)
    Socket = SOCKET_(#AF_IRDA, #SOCK_STREAM, 0)
    If Socket = #ERROR_INVALID_SOCKET
      Socket = 0
      LastError = __GetLastError()
      ProcedureReturn #False
    EndIf
    ProcedureReturn Socket
  EndProcedure
  Procedure ExamineIrdaDevices()
    ;Start examination of Irda Devices
    Protected pDevListLen
    LastError = #ERROR_NONE
    If Socket = 0
      LastError = #ERROR_NO_INIT_NETWORK
      ProcedureReturn #False
    EndIf
    *pDevList = AllocateMemory(4096)
    *pDevList\numDevice = 0
    pDevListLen = MemorySize(*pDevList)
    If getsockopt_(Socket, #SOL_IRLMP, #IRLMP_ENUMDEVICES,
                   *pDevList, @pDevListLen) = #ERROR_INVALID_SOCKET
      LastError = __GetLastError()
      ProcedureReturn #False
    EndIf
    If *pDevList\numDevice = 0
      LastError = #ERROR_NO_MORE_DEVICES
      Debug "No IRDA devices were discovered or cached"
      ProcedureReturn #False
    EndIf
    DeviceNum = 0
    ProcedureReturn #True
  EndProcedure
  Procedure NextIrdaDevice()
    ;Lets examine the next Irda device
    LastError = #ERROR_NONE
    If Socket = 0
      LastError = #ERROR_NO_INIT_NETWORK
      ProcedureReturn #False
    ElseIf *pDevList = 0
      LastError = #ERROR_NO_EXAMINE_IRDA_DEVICES
      ProcedureReturn #False
    ElseIf *pDevList\numDevice = 0
      Lasterror = #ERROR_NO_MORE_DEVICES
      ProcedureReturn #False
    EndIf
    DeviceNum + 1
    If DeviceNum > *pDevList\numDevice
      Lasterror = #ERROR_NO_MORE_DEVICES
      ProcedureReturn #False
    EndIf
    ProcedureReturn #True
  EndProcedure
  Procedure.s GetIrdaDeviceName()
    ;this is th current DeviceName
    LastError = #ERROR_NONE
    If Socket = 0
      LastError = #ERROR_NO_INIT_NETWORK
      ProcedureReturn ""
    ElseIf *pDevList = 0
      LastError = #ERROR_NO_EXAMINE_IRDA_DEVICES
      ProcedureReturn ""
    ElseIf *pDevList\numDevice < DeviceNum
      Lasterror = #ERROR_NO_MORE_DEVICES
      ProcedureReturn ""
    EndIf
    ProcedureReturn PeekS(@*pDevList\Device[DeviceNum -1]\irdaDeviceName[0], -1, #PB_Ascii)
  EndProcedure
  Procedure GetIrdaDeviceID()
    ;this is the current examined DeviceID
    LastError = #ERROR_NONE
    If Socket = 0
      LastError = #ERROR_NO_INIT_NETWORK
      ProcedureReturn #False
    ElseIf *pDevList = 0
      LastError = #ERROR_NO_EXAMINE_IRDA_DEVICES
      ProcedureReturn #False
    ElseIf *pDevList\numDevice < DeviceNum
      Lasterror = #ERROR_NO_MORE_DEVICES
      ProcedureReturn #False
    EndIf
    ProcedureReturn *pDevList\Device[DeviceNum - 1]\irdaDeviceID
  EndProcedure
  Procedure FinishExamineIrda()
    ;Finish examination previously started with
    ExamineIrdaDevices()
    LastError = #ERROR_NONE
    If Socket = 0
      LastError = #ERROR_NO_INIT_NETWORK
      ProcedureReturn #False
    EndIf
    If *pDevList
      FreeMemory(*pDevList)
      *pDevList = 0
    EndIf
    DeviceNum = 0
  EndProcedure
  Procedure Connect(DeviceID)
    ;Connect to the IrDA Decide #DeviceID
    ;You can get the Device ID with the examine procedures:
    ;ExamineDevices(), NextIrdaDevice(), GetIrdaDeviceID(),GetIrdaDeviceName(), FinishExamineIrda()
    LastError = #ERROR_NONE
    If Socket = 0
      LastError = #ERROR_NO_INIT_NETWORK
      ProcedureReturn #False
    ElseIf DestSockAddr\irdaDeviceID <> 0
      LastError = #ERROR_SOCKET_ALREADY_CONNECTED
      ProcedureReturn #False
    EndIf
    DestSockAddr\irdaDeviceID = DeviceID
    If connect_(Socket, @DestSockAddr, SizeOf(SOCKADDR_IRDA)) =#ERROR_INVALID_SOCKET
      DestSockAddr\irdaDeviceID = 0
      LastError = __GetLastError()
      ProcedureReturn #False
    EndIf
    ProcedureReturn #True
  EndProcedure
  Procedure Disconnect()
    ;IF YOU WANT TO REOPEN A IRDA SOCKET, RECALL INIT()!!
    ;A SIMPLE CONNECT() WILL NOT BE ENOUGH!
    LastError = #ERROR_NONE
    If Socket = 0
      LastError = #ERROR_NO_INIT_NETWORK
    Else
      CompilerSelect #PB_Compiler_OS
        CompilerCase #PB_OS_Windows
          If closesocket_(Socket) = #ERROR_INVALID_SOCKET
            LastError = __GetLastError()
          EndIf
        CompilerCase #PB_OS_Linux
          If close_(Socket) = #ERROR_INVALID_SOCKET
            LastError = __GetLastError()
          EndIf
      CompilerEndSelect
    EndIf
    Socket = 0
    DestSockAddr\irdaDeviceID = 0
    ProcedureReturn #True
  EndProcedure
  Procedure SendData(*Buffer, BufferLen)
    ;send data in *Buffer via IrDA
    Protected Length
    LastError = #ERROR_NONE
    If Socket = 0
      LastError = #ERROR_NO_INIT_NETWORK
      ProcedureReturn #False
    ElseIf DestSockAddr\irdaDeviceID = 0
      LastError = #ERROR_NOT_YET_CONNECTED
      ProcedureReturn #False
    EndIf
    Length = send_(Socket, *Buffer, BufferLen, 0)
    If Length = #ERROR_INVALID_SOCKET
      LastError = __GetLastError()
    EndIf
    ProcedureReturn Length
  EndProcedure
  Procedure IsDataAvailable()
    ;Checks if data is available and will then return the amount
    ;of Data waiting.
    ;similar to AvailableSerialPortInput
    Protected Length
    If Socket = 0
      LastError = #ERROR_NO_INIT_NETWORK
      ProcedureReturn -1
    ElseIf DestSockAddr\irdaDeviceID = 0
      LastError = #ERROR_NOT_YET_CONNECTED
      ProcedureReturn -1
    EndIf
    CompilerSelect #PB_Compiler_OS
      CompilerCase #PB_OS_Windows
        ioctlsocket_(Socket, #FIONREAD, @Length)
      CompilerCase #PB_OS_Linux
        ioctl_(Socket, #FIONREAD, @Length)
    CompilerEndSelect
    ProcedureReturn Length
  EndProcedure
  Procedure ReceiveData(*Buffer, BufferLen)
    ;Receive data from the IrDA into *Buffer
    ;Will return the length it has been received.
    Protected Length
    LastError = #ERROR_NONE
    If Socket = 0
      LastError = #ERROR_NO_INIT_NETWORK
      ProcedureReturn #False
    ElseIf DestSockAddr\irdaDeviceID = 0
      LastError = #ERROR_NOT_YET_CONNECTED
      ProcedureReturn #False
    EndIf
    Length = recv_(Socket, *Buffer, BufferLen, 0)
    If Length = #ERROR_INVALID_SOCKET
      LastError = __GetLastError()
    EndIf
    ProcedureReturn Length
  EndProcedure
  Procedure GetSockID()
    ;Get the os handle of our socket
    If Socket = 0
      LastError = #ERROR_NO_INIT_NETWORK
      ProcedureReturn #False
    EndIf
    ProcedureReturn Socket
  EndProcedure
  Procedure GetLastError()
    ProcedureReturn LastError
  EndProcedure
EndModule
;Example Code
CompilerIf #PB_Compiler_IsMainFile
  Procedure.s ParseErrorMessages()
    Protected Error, Result.s
    Select IrDA::GetLastError()
      Case IRDA::#ERROR_NONE
        Result = "There were no error!"
      Case IRDA::#ERROR_NO_INIT_NETWORK
        Result = "It seems you have network problems ordidn't call IRDA::Init()!"
      Case IRDA::#ERROR_NETWORK_DOWN
        Result = "Network down!"
      Case IRDA::#ERROR_NO_IRDA_SUPPORT
        Result = "Check that the local computer has an infrared device And a device driver is installed!"
      Case IRDA::#ERROR_NO_MORE_DEVICES
        Result = "No (more) IrDA deviced found"
      Case IRDA::#ERROR_ADDRESS_IN_USE
        Result = "The Socket seems to be in use!"
      Case IRDA::#ERROR_NO_MEMORY
        Result = "Memory problems!"
      Case IRDA::#ERROR_PROTOCOL_NOT_SUPPORTED
        Result = "The protocol is not supported?!"
      Case IRDA::#ERROR_PROTOCOLTYPE_WRONG
        Result = "Wrong protocol type!"
      Case IRDA::#ERROR_NOT_YET_CONNECTED
        Result = "The socket is not connected!"
      Case IRDA::#ERROR_SOCKET_ALREADY_CONNECTED
        Result = "This socket is already connected!"
      Case IRDA::#ERROR_NO_EXAMINE_IRDA_DEVICES
        Result = "You didn't call IRDA::ExamineIrdaDevices() first!"
      Case IRDA::#ERROR_TIMED_OUT
        Result = "Request timed out!"
    EndSelect
    ProcedureReturn Result
  EndProcedure
  Procedure main()
    Protected i
    If IrDA::Init() = #False
      Debug "Init failed!"
      Debug ParseErrorMessages()
      ProcedureReturn
    EndIf
    If IrDa::ExamineIrdaDevices()
      While IrDA::NextIrdaDevice()
        Debug IrDA::GetIrdaDeviceName()
        Debug IrDA::GetIrdaDeviceID()
        i = IrDA::GetIrdaDeviceID() ;<- keep the first device in mind
      Wend
      IrDA::FinishExamineIrda()
      If IrDA::Connect(i)
        Debug "ok"
        Debug IrDA::Disconnect()
      Else
        Debug "Connection failed!"
        Debug ParseErrorMessages()
      EndIf
    Else
      Debug "Examination failed!"
      Debug ParseErrorMessages()
    EndIf
  EndProcedure
  main()
CompilerEndIf 
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Ollivier
Messages : 4190
Inscription : ven. 29/juin/2007 17:50
Localisation : Encore ?
Contact :

Re: pbi pour périphérique IrDA

Message par Ollivier »

Ar-S a écrit :Le même avec l'identation (Ctrl+a puis Ctrl +i dans l'ide)
C'est plus lisible.
Fameuse combinaison de touches que ma personne ne connaissait pas...
Avatar de l’utilisateur
Kwai chang caine
Messages : 6962
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: pbi pour périphérique IrDA

Message par Kwai chang caine »

Et ben moi non plus, je me tapais tout à la mano :|
Maintenant j'arrête pas. .ctrl +i par ci, ctrl+ i par la... :D
Merci Ars 8)
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Ollivier
Messages : 4190
Inscription : ven. 29/juin/2007 17:50
Localisation : Encore ?
Contact :

Re: pbi pour périphérique IrDA

Message par Ollivier »

Merci TazNormand!
Avatar de l’utilisateur
Kwai chang caine
Messages : 6962
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: pbi pour périphérique IrDA

Message par Kwai chang caine »

Merci taz
En fait des raccourcis clavier j'en utilise pas mal.
Pas ceux qui nécessitent la touche windows, car quitte à faire pleurer une nouvelle fois Falsam, mes claviers sont souvent des vieux ibm (j'adore leur bruit :mrgreen: ) donc pas de touche windows.
Puis c'est pareil trop de raccourcis tuent...
Je pense que chacun pioche dans ceux qui lui conviennent le mieux

Mais pour ce qui concerne l'ide de pb, c'est différent.
Je trouve que bien trop souvent on découvre une fonction 2 ans après.
Et pourtant je lis la liste des nouveautés quand fred créé une nouvelle version.
Mais bien souvent ça tient en une ligne :|
Alors pas toujours facile de comprendre la nouvelle fonction sans photos, exemple simple, démonstration.

La seule que je pense pouvoir comprendre en une ligne, voir même en 1 mot, c'est la gestion complète des gifs :mrgreen:
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Marc56
Messages : 2148
Inscription : sam. 08/févr./2014 15:19

Re: pbi pour périphérique IrDA

Message par Marc56 »

Kwai chang caine a écrit :Je pense que chacun pioche dans ceux qui lui conviennent le mieux
Quand je faisais un Win+E sur les postes de mes utilisateurs au lieu d'aller chercher l'icône au fin fond des menus ils étaient sciés 8O
Quand je faisais CTRL+A, CTRL+C, WIN+E, CTRL+V dans une autre fenêtre, il me voyaient comme un demi-dieu 8)
... le lendemain, ils avaient tout oublié :) :( :? :roll: :mrgreen: dure la vie d'administrateur systèmes.
Kwai chang caine a écrit :Je trouve que bien trop souvent on découvre une fonction 2 ans après.
D'où l'intérêt de parcourir toutes les branches de l'arbre à chaque nouvelle version.
Kwai chang caine a écrit :Alors pas toujours facile de comprendre la nouvelle fonction sans photos, exemple simple, démonstration.
Pourtant pour cela on est bien servi dans l'aide, il y a un exemple pour presque chaque fonction, voir parfois un programme complet.
Kwai chang caine a écrit :La seule que je pense pouvoir comprendre en une ligne, voir même en 1 mot, c'est la gestion complète des gifs :mrgreen:
Ah, si la 5.40 pouvait avoir la gestion du format GIF (même non animé)
:wink:
Avatar de l’utilisateur
Kwai chang caine
Messages : 6962
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: pbi pour périphérique IrDA

Message par Kwai chang caine »

D'où l'intérêt de parcourir toutes les branches de l'arbre à chaque nouvelle version.
Tu sais si je n'ai pas un but précis, je n'arrive pas à faire coincider la théorie à la pratique.
Je dit...coool quand je fais un essais et quelques mois plus tard, je me demande comment je pourrais faire pour faire la même chose.
Il m'arrive même de chercher une solution dans le forum, de cliquer sur un sujet en me disant : "Classe !!! le pelo il a eu le même probleme que moi !! je vais trouver ma solution"..sauf que le pelo...c'est KCC mais 3 ans auparavant :roll:
Au fil des années, j'ai l'impression de tourner en rond, qui a dit qu'il ne fallait pas réinventer la roue ??? :mrgreen:

C'est ça la dure peine des inhibés du bulbe, à la maniere d'un tuyau, ce qui entre d'un coté fait sortir quelque chose à l'autre bout
Et puis y'a tellement de branches maintenant, que pour trouver les nouvelles....faudrait que FRED les mette en couleur :lol:
Pourtant pour cela on est bien servi dans l'aide, il y a un exemple pour presque chaque fonction, voir parfois un programme complet.
Oui j'ai honte
Je n'ai jamais aimé lire depuis ma plus tendre enfance, c'est pourquoi j'ai été viré rapide du cycle d'étude "normal" :| mais causer oui !!! :mrgreen:
Je ne lis jamais les docs, que ce soit pour les meubles, les appareils electroniques, les outils, etc.. et pourtant j'en aurais mis en branle des trucs neufs dans ma vie :oops:

Quel gland, quand je pense au temps qu'il faut pour en faire une, je pourrais au moins avoir le respect pour l'auteur qui a mis X fois plus de temps pour la rediger que j'en aurais mis pour la lire (J'exclue volontairement les docs made in china traduite avec les pieds :? :mrgreen:)

C'est bien souvent que je comprend la fonction d'un outil ou autre au moment ou je le vend..quand c'est pas l'acheteur qui me l'explique 8O :lol:

C'est pourquoi pour mes giciel, j'en fait jamais, et en plus je planque souvent les boutons dans des skins
Je te parle pas de la gueule des clients (On est un clown ou on l'est pas, non ??) :lol:
Image
Je fait tout pour que mes applis ne soient pas buggué, c'est ma fierté, mais au final, c'est toute l'appli qui est un bug à elle toute seule.
Car le plus dur, c'est que comme j'ai pas de mémoire, un mois aprés, je suis même pas foutu d'utiliser mes propres logiciels, alors expliquer à "quinquin" d'autre...même pas j'y pense :lol:
Je suis peut être le premier concepteur d'applis éphémere 8)

Alors tu vois, si y'a pas des images qui bougent, des petits dessins, des pouets pouets et des gling gling...je suis pas pres de grimper dans ton arbre à doc :mrgreen:
Ah, si la 5.40 pouvait avoir la gestion du format GIF (même non animé)
Que les dieux t'entendent ...
Si si ....animé....animé ..... :mrgreen:
Image
Quand je faisais CTRL+A, CTRL+C, WIN+E, CTRL+V dans une autre fenêtre, il me voyaient comme un demi-dieu
Tu as raison...les raccourcis claviers ça la pete, ça epate tout le monde ...même moi parfois 8)

Comme j'ai des doigts comme les cuisses d'une fille, et que le week end je manipule plutôt les baramines et les massettes que les claviers
J'ai la facheuse tendance à m'exploser le bout des doigts à la maniere des années 50, quand la regle dans les mains des maitres de l'époque, avait une toute autre fonction que de tirer des traits :?
Ce qui fait que bien souvent quand j'écris des placards, non content de faire souffrir les yeux de mes "chers et tendres lecteurs" suivez mon regard... :mrgreen:
Et outre la douleur, je me retrouve avec la sensation d'avoir raccourci mes phalanges de 5 cm à la fin de ma prose :|

Mais pour en revenir au rayon "épatage", grâce à cette auto mutilation digitale quotidienne,
mes collegues croient tous que je suis le "jerry lewis" du clavier


Image

Que je tape what milles mots minutes, tellement je fais du bruit :mrgreen:
Je me suis donc fait en toute inpunité, outre une réputation de bill gates, une réputation de dactylo.

Comme quoi dans la vie, pour être reconnu et vénéré, le vieil adage se vérifie toujours :
il faut mieux faire savoir, que savoir faire :mrgreen:
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Avatar de l’utilisateur
TazNormand
Messages : 1294
Inscription : ven. 27/oct./2006 12:19
Localisation : Calvados (14)

Re: pbi pour périphérique IrDA

Message par TazNormand »

[Mode Copier-Coller de réponse=ON]
Bon, je sais que tu tournes avec un 80286 sur batterie, Ollivier, mais pourrais-tu mettre un peu plus d'explications sur ton premier message de ce topic, s'il te plaît ?
[Mode Copier-Coller de réponse=OFF]
Image
Image
Ollivier
Messages : 4190
Inscription : ven. 29/juin/2007 17:50
Localisation : Encore ?
Contact :

Re: pbi pour périphérique IrDA

Message par Ollivier »

@Taz

Pas de réponse de ta part? Sujet entier à supprimer, s'il vous plaît.
Ollivier
Messages : 4190
Inscription : ven. 29/juin/2007 17:50
Localisation : Encore ?
Contact :

Re: pbi pour périphérique IrDA

Message par Ollivier »

Idem sauvegardé, comme ça, pas de problème.
Avatar de l’utilisateur
TazNormand
Messages : 1294
Inscription : ven. 27/oct./2006 12:19
Localisation : Calvados (14)

Re: pbi pour périphérique IrDA

Message par TazNormand »

Pourquoi supprimer le topic, il peut servir à d'autres.

Il est vrai que GallyHC a demandé en premier un peu plus d'informations, et je suis d'accord avec lui, tu peux pas balancer un code ou un lien comme ça sans un minimum d'explications, ou au moins traduire ce qu'a écrit Hexor à propos de ce code, beaucoup de membres, comme l'a fait remarquer KCC dans les messages que j'ai un peu trop rapidement effacé (encore désolé :oops: ), tout le monde ne maîtrise ou ne comprend pas l'anglais.

Je mets à jour ton premier message :wink: .
Image
Image
Répondre