FpIOCTL lazarus / 32-Linux ---------------------------------------------------------------------- fabricemg · 2012-07-23 09:05 Hello, I need help for FpIOCtrl I want to open 1 DVB-T stick usb with Lazarus. I use FpIOCTL for open /dev/dvb/adapter0/frontend0 , the result is a FileDescriptor Code: [Select] fd:= FpOpen('/dev/dvb/adapter0/frontend0', _O_RdWr) after , i want to acces a data with Code: [Select] result := FpIOCtl(fd, 61, @dvb_frontend_info)  dvb_frontend_info have a good definition Code: [Select]type   // Frontend type   // FE_QPSK =  DVB-S   // FE_QAM = DVB-C   // FE_OFDM = DVB-T   fe_type = (     FE_QPSK,     FE_QAM,     FE_OFDM,     FE_ATSC);   // frontend capabilities   fe_caps = (     FE_IS_STUPID = $0,     FE_CAN_INVERSION_AUTO = $1,     FE_CAN_FEC_1_2 = $2,     FE_CAN_FEC_2_3 = $4,     FE_CAN_FEC_3_4 = $8,     FE_CAN_FEC_4_5 = $10,     FE_CAN_FEC_5_6 = $20,     FE_CAN_FEC_6_7 = $40,     FE_CAN_FEC_7_8 = $80,     FE_CAN_FEC_8_9 = $100,     FE_CAN_FEC_AUTO = $200,     FE_CAN_QPSK = $400,     FE_CAN_QAM_16 = $800,     FE_CAN_QAM_32 = $1000,     FE_CAN_QAM_64 = $2000,     FE_CAN_QAM_128 = $4000,     FE_CAN_QAM_256 = $8000,     FE_CAN_QAM_AUTO = $10000,     FE_CAN_TRANSMISSION_MODE_AUTO = $20000,     FE_CAN_BANDWIDTH_AUTO = $40000,     FE_CAN_GUARD_INTERVAL_AUTO = $80000,     FE_CAN_HIERARCHY_AUTO = $100000,     FE_CAN_8VSB = $200000,     FE_CAN_16VSB = $400000,     FE_HAS_EXTENDED_CAPS = $800000,   // We need more bitspace for newer APIs, indicate this.     FE_CAN_TURBO_FEC = $8000000,  // frontend supports "turbo fec modulation"     FE_CAN_2G_MODULATION = $10000000, // frontend supports "2nd generation modulation" (DVB-S2)     FE_NEEDS_BENDING = $20000000, // not supported anymore, don't use (frontend requires frequency bending)     FE_CAN_RECOVER = $40000000, // frontend can recover from a cable unplug automatically     FE_CAN_MUTE_TS = $80000000  // frontend can stop spurious TS data output     );   // frontend information   dvb_frontend_info = record     Name: array[0..127] of char;     type_dvb: fe_type;     frequency_min: cuint32;     frequency_max: cuint32;     frequency_stepsize: cuint32;     frequency_tolerance: cuint32;     symbol_rate_min: cuint32;     symbol_rate_max: cuint32;     symbol_rate_tolerance: cuint32;        // ppm     notifier_delay: cuint32;           // ms     caps: fe_caps;   end; definition in C isCode: [Select] #define FE_GET_INFO                _IOR('o', 61, struct dvb_frontend_info) but I have always result = -1 (error) a idéa? , where is my mistake? ---------------------------------------------------------------------- ludob · 2012-07-23 18:13 _IOR is a macro that combines the 3 parameters into 1 integer value. In this case it will translate into Code: [Select]FE_GET_INFO                 = Integer(-2136445123); Have a look at this open source VirtualSTBViewer which has many more ioctl constants defined for DVB: http://www.koders.com/delphi/fidE725487ED90396C9BF3BE407F0FA0B7CE9BE81 FD.aspx?s=network Edit: to be complete, you need to do Code: [Select]result := FpIOCtl(fd, FE_GET_INFO, @dvb_frontend_info) ---------------------------------------------------------------------- fabricemg · 2012-07-23 18:33 Thanks ludob I have downloaded this project  few days ago, but I don't have seen this unit  Did you have a information for combine the 3 parameters into 1 integer value? ---------------------------------------------------------------------- ludob · 2012-07-23 19:20 The definition is in sys/ioctl.h. For example: http://unix.superglobalmegacorp.com/Net2/newsrc/sys/ioctl.h.html (these definitions can change between different *nix systems!) Code: [Select]#define _IOR(g,n,t) _IOC(IOC_OUT, (g), (n), sizeof(t)) #define _IOC(inout,group,num,len)  (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num)) #define IOC_OUT 0x40000000 /* copy out parameters */ #define IOC_IN 0x80000000 /* copy in parameters */ #define IOCPARM_MASK 0x1fff /* parameter length, at most 13 bits */ So _IOR('o', 61, struct dvb_frontend_info) becomes Code: [Select]$40000000 or (sizeof(dvb_frontend_info) and $1fff) shl 16 or ord('o') shl 8 or 61 = $40000000 + 168 shl 16 + 111 shl 8 + 61 = $40A86F3D Now -2136445123 is $80A86F3D which corresponds with _IOW according to above definition. ---------------------------------------------------------------------- fabricemg · 2012-07-24 19:00 Thank you very much ludob