登录注册
社区应用 最新帖子 精华区 社区服务 会员列表 统计排行
主题 : [ZT]我和电脑亲密接触的心路历程
伍胥之 离线
级别: 军区司令员

显示用户信息 
80楼  发表于: 2015-09-05   
引用
引用第20楼newport93于06-14-2010 13:47发表的  : *z`_U]tP  
OS6 l*S('  
老五,I 服了U。 >v@R]9  
7=t4;8|j;  
哪一天等俺退休了,也写一个The Non-Progamming career of an ex-programmer。哈哈哈。。。。。 rl9YB %P  
DPJ#Y -0  
[Z|R-{"  
新港妹妹,虽然你还没有退休,但是孩子读了大学你应该有些时间了嘛!就开帖写吧!我们很想看啊! 也特别想看看你的non-programming career中的恋爱史啊! V2cLwQ'0  
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
81楼  发表于: 2015-09-05   
引用
引用第3楼阿散于03-19-2010 22:49发表的  : Z:W6@j-~  
Is that what you wanted to express yourself to us with the whole blank message but the very big title? *{8K b>D  
kD S  
VS<E?JnbFV  
阿散这个家伙,已经被我全局禁言了,但是在他不犯错的时候,也还是个很好玩的同学。
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
82楼  发表于: 2015-09-05   
引用
引用第6楼沧桑于06-13-2010 14:39发表的  : DVt;I$  
老伍在写交代材料啊,而且写在一个ZT的贴下,哈哈。 SuU,SE'TX  
z=B*s!G  
YU.aZdA&V3  
这不是怕您见笑嘛!现在露馅了,只得继续招供了。 J`a$"G B.  
%KK6}d #  
可以从宽不?
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
83楼  发表于: 2015-09-05   
引用
引用第10楼卡拉于06-13-2010 21:49发表的  : <QFT>#@T  
老伍,对不住,我把你原来的英文标题改了,太不吸引人眼球了,有些人还当是英文的都不会去点击。我通篇读了一下,改成了现在的标题。如果你不喜欢,可以改回来。 iTF`sjL  
Z .VIb|  
#qY`xH'>  
其实标题没有什么,卡总既然改了就不必再改回了。 } #5V t  
UXwnE@`F  
主要是当初写的时候真是顶着锅盖写的。 )isz }?Dj  
hAtf)  
阿散说得对。我就是把一堆鸡毛蒜皮的小事,用了一个big title.
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
84楼  发表于: 2015-09-05   
引用
引用第16楼阿平于06-13-2010 22:25发表的  : ,F }\njL  
哦, 打倒忽悠大家的家伙.      I!sh+e  
ZYRZ$87jZ  
Wk<heF  
阿平姐,这可不是忽悠,我可是认真交待经历呢!
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
85楼  发表于: 2015-09-05   
引用
引用第17楼阿散于06-13-2010 22:29发表的  : J>D+/[mFt  
每个人的故事对其他人都是故事, 1M@OBfB8  
自己的故事也是其中之一. fv@mA--  
跳出来看, M9[52D!{  
不过是众人中的一个人的故事. zD}@QoB  
YA+jLy6ZL  
所以,接着听故事. rgq~lZ.U4K  
8w4-Ud*$i  
女人们有兴趣的就等老伍开个新帖或者跟贴, \vg(@)$q   
听他痛说恋爱革命历史.... @QOlo -u  
@nWhUH%  
杂家接着听他自学程序员历史, L As#g||M  
高级程序员考了吗?  Y7*8 A,  
|!t &ZpdD  
*LuR <V  
这个恋爱革命史还是等你痛改前非换个新ID来讲吧! =n@"lY u[  
au=A+  
我什么程度员也没有考过,连大学生的计算机应用等级证明都没有。 v@,n]"  
wPr9N}rf  
我唯一考过的计算机科目是职称评审时要求有证书,所以我用了半小时考了word, powerpoint,和internet基础。都是小儿科的东东。如果没有用VBA写个Word的宏,我都觉得对不起微软了。 ~l {*XM  
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
86楼  发表于: 2015-09-05   
引用
引用第21楼阿散于06-14-2010 22:33发表的  : s+m3&(X  
引用第19楼伍胥之于06-14-2010 12:33发表的  : D;1?IeS  
ztS:1\  
SI)QX\is8  
我平生唯一参加的计算机考试就是职称考试,任选4个模块。 -G'U\EXT  
w ak:"B[  
我连一级也没有考过。  _BFDsQ  
.
g49G7sk  
mV>l`&K=  
引用
q g2 fTe  
矬子里拔将军... Yamu"#  
你们那里的俗语是吧? {{:QtkN  
~`Y!_'(x  
我们这里说"矮子里拔长脚"..应该是同一个意思... k2 _i;v  
s78MXS?py  
有趣....各地有表达意思一样却方式不同的俗语.... }yzCq+  
[,bra8f[C  
^5'pJ/BV  
你的文章写的有脸皮,没屁眼的, !l(D0 C  
让看客大为不满... @GVONluyU`  
uqotVil,  
你等着,,估计你以后接到的午夜凶铃就多了... :?!b\LJ2^  
hr@kU x  
']bw37_U,  
我到现在也没有接到你的午夜凶铃呢! #Vy8<Vy&w  
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
87楼  发表于: 2015-09-05   
引用
引用第25楼猪小秘于01-20-2011 20:51发表的  : F$sDmk#  
伍SIR,再次抱拳佩服 Hk8lHja+\  
7!;H$mxP  
 ,*kh{lJ  
小秘倒是好久不见了呢!宝贝几岁了?很健康活泼吧?
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
88楼  发表于: 2015-09-05   
Re:回 38楼(伍胥之) 的帖子
引用
引用第39楼suehan234于01-22-2011 08:00发表的 回 38楼(伍胥之) 的帖子 :  ;?G..,  
佩服,玩也玩得这么专业! [.Rdq]w6  
6}cN7wnm j  
^ 'ws/(  
只是票友而已,算不上专业的。
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
89楼  发表于: 2015-09-05   
引用
引用第46楼清水于03-03-2011 14:50发表的  : 5m yQBKE  
r3NdE~OAi  
介个真的看不懂。 2b/Cs#-  
你说你老啦,喜欢怀旧了,才想起来填坑。 {%oxzdPc  
提醒我也想想,是不是也老啦,是不是也有坑没填呢。 D0}r4eA  
onU\[VvM  
R $@$  
你肯定有许多坑没有填,但是我挖的坑更多,但同是我也在你的某个坑里等你填埋呢!
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
90楼  发表于: 2015-09-05   
//从指定扇区号dwSector开始,写dwLength长度的数据 gtnu/ Q  
BOOL WriteDisk( HANDLE hpartition, DWORD dwSector, DWORD dwLength, char* lpBuffer){ gW-mXb  
DWORD dwCB; I8/tD|3  
LARGE_INTEGER  offset; LP'wL6#  
offset.QuadPart  =  UInt32x32To64(dwSector ,  512); LC4W?']/  
SetFilePointer(hpartition,  offset.LowPart,  &offset.HighPart,  FILE_BEGIN); {G+iobQdd  
if(!WriteFile(hpartition, lpBuffer, dwLength * 512, &dwCB, NULL)){ (h|E@gRa  
DWORD error = GetLastError(); feJl[3@tO  
MessageBox(NULL,"写入文件失败!",NULL,IDOK); [(2XL"4D  
return FALSE; \<HY'[gr  
} @\WeI"^F8  
return TRUE; +~V)&6Vn  
} T0{X,  
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
91楼  发表于: 2015-09-06   
'VB 6.0 版 )x<BeD  
'这不是我写的,它更强悍了。因为可以直接读写物理扇区(CHS),而不是逻辑扇区。 F/cA tT.M?  
@A|#/]S1  
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long :Y|[?;  
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long g`w46X  
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Long) As Long '//declare has changed W9QVfe#s  
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long '//declare has changed c,:nWf  
Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long  [a_o3  
'如果用绝对扇区写,那么文件的建立打开都不能用VB的 open 语句了。 _SnD)k+TgJ  
S%j W} v';  
}]Nt:_UCX  
Private Const GENERIC_READ = &H80000000 &O5O@3:7]  
Private Const GENERIC_WRITE = &H40000000 H*P[tyz$  
U4[GA4DZ   
Private Const FILE_SHARE_READ = &H1 8O_yZ ~Z4  
Private Const FILE_SHARE_WRITE = &H2 @)C.IQ~  
Private Const OPEN_EXISTING = 3 7GvMKtuSK  
Q-7L,2TL  
Private Const INVALID_HANDLE_VALUE = -1 M0T z('~s  
HQNpf1=D  
'//file seek V`8\)FFG  
Private Const FILE_BEGIN = 0 Sf*gAwnW  
Private Const FILE_CURRENT = 1 ~RH)iI  
Private Const FILE_END = 2 "yc|ng  
<.2jQ#So  
Private Const ERROR_SUCCESS = 0& Ciy%7_~\  
N@Q_5t0bk  
'//device io control pL . 0_  
Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, ByVal lpOverlapped As Long) As Long =!G{+& j  
>Q=Q%~  
Private Const IOCTL_DISK_GET_DRIVE_GEOMETRY As Long = &H70000   '458752 DkSs^ym  
Private Const IOCTL_STORAGE_GET_MEDIA_TYPES_EX  As Long = &H2D0C04 <Uc  
Private Const IOCTL_DISK_FORMAT_TRACKS As Long = &H7C018 B1A:}#  
Private Const FSCTL_LOCK_VOLUME As Long = &H90018 ?G<ISiABQC  
Private Const FSCTL_UNLOCK_VOLUME As Long = &H9001C ~9PZ/( '  
Private Const FSCTL_DISMOUNT_VOLUME As Long = &H90020 +KaVvf  
Private Const FSCTL_GET_VOLUME_BITMAP = &H9006F u @;e`-@  
D/afa8>LQH  
'//type R9  Y@I  
Private Type LARGE_INTEGER y\ })C-&  
    lowpart As Long {:|b,ep T  
    highpart As Long +sV~#%%  
End Type -Jf}3$Ra  
"|Kag|(qB  
Private Enum MEDIA_TYPE yp[,WZt  
    Unknown D"2bgw  
    F5_1Pt2_512 ^#XQ2UN  
    F3_1Pt44_512 "}Ikx tee  
    F3_2Pt88_512 ((&5F!+\-  
    F3_20Pt8_512 ]:;dJc'  
    F3_720_512 BT`g'#O  
    F5_360_512 & WeN{  
    F5_320_512 :H:Se  
    F5_320_1024 ia (&$a8X  
    F5_180_512 )}P/xY0  
    F5_160_512 4bcd=a;  
    RemovableMedia r@}8TE*|P  
    FixedMedia ^]D+H9Tl  
End Enum /|lAxAm?  
Bg] %  
Private Type DISK_GEOMETRY ^X?uAX-RP|  
    Cylinders           As LARGE_INTEGER o7 0] F  
    MediaType           As MEDIA_TYPE xS:n  
    TracksPerCylinder   As Long l" 7#(a  
    SectorsPerTrack     As Long "jLC!h^N  
    BytesPerSector      As Long RL )~J4Y  
End Type 'Z]wh.]T  
cvQAo|  
'//private vars /=T:W*C  
Private hDisk           As Long             'disk handle @j"6f|d  
Private lpGeometry      As DISK_GEOMETRY    'disk info <xe_t=N  
Private lBufferSize     As Long             'the buffer size of read/write }KO <II  
=\ k:]  
Public Function OpenDisk(ByVal FileName As String) As Boolean LIrebz  
'// 打开磁盘 ; !C_}P  
    hDisk = CreateFile(FileName, _ w IP4Z^  
                        GENERIC_READ Or GENERIC_WRITE, _ |MOz> 1<a  
                        FILE_SHARE_READ Or FILE_SHARE_WRITE, _ {5fL!`6w  
                        ByVal 0&, _ ~ToU._  
                        OPEN_EXISTING, _ :>/6:c?atG  
                        0, _ ! ,0  
                        0) D&@Iuo  
    OpenDisk = Not (hDisk = INVALID_HANDLE_VALUE) -$X4RS  
End Function mlPvF%Ba  
G8 q<)  
Public Function CloseDisk() As Boolean zkiwFEHA=  
'//关闭磁盘 e0#t  
    CloseDisk = CloseHandle(hDisk) Abi(1nXdQ  
End Function 80`$F{xcX  
>_\[C?8  
Public Function GetDiskGeometry() As Boolean hzU(XW  
'//获取磁盘参数 "LSzF_mK  
    Dim dwOutBytes      As Long ^KnK \  
    Dim bResult         As Boolean #WJ*)$A@&  
     d"n"A?nXh  
    bResult = DeviceIoControl(hDisk, _ EqGpo_  
                                IOCTL_DISK_GET_DRIVE_GEOMETRY, _ 8.>himL  
                                ByVal 0&, 0, _ 0yvp>{;p  
                                lpGeometry, Len(lpGeometry), _ 1*|/N}g)  
                                dwOutBytes, _ \ @[Q3. VX  
                                ByVal 0&) 1Vx5tOq  
     .lq83; k  
    If bResult Then lBufferSize = lpGeometry.BytesPerSector * lpGeometry.SectorsPerTrack [ [pt~=0  
    GetDiskGeometry = bResult S;y4Z:!  
End Function IA{W-RRb  
$4}G  
Public Sub GetDiskInfo(MediaType As Long, _ >t<\zC|~w  
                        Cylinders As Long, _ Ndmw/ae  
                        TracksPerCylinder As Long, _ "$aoIXv  
                        SectorsPerTrack As Long, _ c-v-U O%  
                        BytesPerSector As Long) T:Ovh.$  
'//返回磁盘的参数 rLE+t(x(0  
    MediaType = lpGeometry.MediaType hsT&c|  
    Cylinders = lpGeometry.Cylinders.lowpart GwfCl{l  
    TracksPerCylinder = lpGeometry.TracksPerCylinder A2;6Vz=z  
    SectorsPerTrack = lpGeometry.SectorsPerTrack MTN*{ug2:  
    BytesPerSector = lpGeometry.BytesPerSector -SfU. XlZl  
rL&Mq}7QK  
End Sub bdLi _k  
ktS^^!,l%  
Public Property Get BufferSize() As Long L`e19I$  
'//返回每次读/写的缓冲大小 9 UVT]acq  
    BufferSize = lBufferSize d S'J@e=#  
End Property ~@)s)K  
1;DRcVyS+  
2Y<]X7Ch:  
Public Function LockVolume() As Boolean ? |#dGk g  
'// 将卷锁定 B^]PKjLNZ  
    Dim dwOutBytes  As Long rlA/eQrS  
    Dim bResult     As Boolean YRCs&tgs  
     <5,|h3]-#  
    bResult = DeviceIoControl(hDisk, _ znPh7{|<  
                                FSCTL_LOCK_VOLUME, _ &r~s3S{pQ  
                                ByVal 0&, 0, _ /%s:aO  
                                ByVal 0&, 0, _ RKE"}|i +S  
                                dwOutBytes, _ 2P)O 0j\/  
                                ByVal 0&) 7(oA(l1V  
    LockVolume = bResult e(xuy'4r  
End Function 4P"bOt5izR  
KQvSeH>r  
15q^&l[Q  
Public Function UnlockVolume() As Boolean I{r*Y9  
'// 将卷解锁 K[ [6A:  
    Dim dwOutBytes As Long {~u Ti>U  
    Dim bResult As Boolean }r!+wp   
     vf$IF|  
    bResult = DeviceIoControl(hDisk, _ b$%Kv(  
                                FSCTL_UNLOCK_VOLUME, _ #9Jr?K43  
                                ByVal 0&, 0, _ G~v:@  
                                ByVal 0&, 0, _ !_ QT{H  
                                dwOutBytes, _ O`@- b#  
                                ByVal 0&) HsUh5;  
    UnlockVolume = bResult k& +gkJm  
End Function oP9 y@U  
w^ OB  
dq`{fqGl  
Public Function DismountVolume() As Boolean IM7<z,*oF  
'// 将卷卸下,使系统重新辨识磁盘,等效于重新插盘 H17I" 5N  
    Dim dwOutBytes As Long K!.t}s.t  
    Dim bResult As Boolean *z)gSX  
     AS@(]T#R  
    bResult = DeviceIoControl(hDisk, _ l)dE7$H  
                                FSCTL_DISMOUNT_VOLUME, _ "M!m-]  
                                ByVal 0&, 0, _ \D(3~y>  
                                ByVal 0&, 0, _ gua7<z6=eh  
                                dwOutBytes, _ %Zbm%YaW5  
                                ByVal 0&) zTj ie  
    DismountVolume = bResult {wsJ1 v8!  
End Function $A-X3d;'\/  
 oC*a;o  
@4D{lb"{  
Public Function ReadDisk(ByVal Cylinders As Long, _ |Tc4a4jS  
                    ByVal Tracks As Long, _ u '/)l}  
                    db() As Byte) As Boolean Q$:Q6 /5.  
'//按柱面和磁道来读取磁盘数据 $+ _1F`  
    Dim iPos    As Long aK95&Jyw&  
    Dim lRead   As Long 7s#8-i  
     w$AR  
    iPos = Cylinders * Tracks * lBufferSize N%xCyZ  
     R ZQH#+*t}  
    If SeekAbsolute(0, iPos) Then m O]>]   
        ReadDisk = ReadBytes(lBufferSize, db(), lRead) -egnMc67  
    End If j6Sg~nRh  
End Function ]K*R[  
e,VF;Br  
Public Function WriteDisk(ByVal Cylinders As Long, _ 'j<u0'K@  
                     ByVal Tracks As Long, _ 5h`LWA B  
                     db() As Byte) As Boolean ZQ+DAX*MS  
'//按柱面和磁道来写磁盘数据 Btm _S\1  
    Dim iPos    As Long 7=9>yba)^  
    Dim lRead   As Long k&%i+5X  
     zfv@<'  
    iPos = Cylinders * Tracks * lBufferSize 9Dgs A`{$  
     9#@s(s  
    If SeekAbsolute(0, iPos) Then ~/9RSdv7  
        WriteDisk = WriteBytes(lBufferSize, db()) K%+4M#jj5  
    End If `=P_ed%&'  
End Function kHylg{i{"  
op5 `#{  
FZ ?eX`,  
'/////////////////////////////////////////////////////////////////////////////////////  \20} /&  
'//file system q(:L8nKT]  
Zfcf?&><  
Private Function SeekAbsolute(ByVal HighPos As Long, ByVal LowPos As Long) As Boolean GT)7VFrL  
'//seek file A8{ xZsH  
    '//Notice: when you set LowPos=5, the read/write will begin with the 6th(LowPos+1) byte Q,^/Lm|]k  
    LowPos = SetFilePointer(hDisk, LowPos, HighPos, FILE_BEGIN) ! CcDA/0  
    If LowPos = -1 Then [}ja \!P  
        SeekAbsolute = (Err.LastDllError = ERROR_SUCCESS) MO0NNVVi%U  
    Else 1=C12  
        SeekAbsolute = True .ex;4( -!  
    End If bTmhz  
     =g! Pw]  
End Function #` gu<xlW  
ThgJ '  
L;u5  
Private Function ReadBytes(ByVal ByteCount As Long, ByRef DataBytes() As Byte, ByRef ActuallyReadByte As Long) As Boolean N+B!AK0.  
'//read data to array W h9L!5  
    Dim RetVal    As Long |[Fb&x  
    RetVal = ReadFile(hDisk, DataBytes(0), ByteCount, ActuallyReadByte, 0) ~{tO8 ]  
    'ActuallyReadByte =>> if the bytesRead=0 mean EOF E V)H>kM  
    ReadBytes = Not (RetVal = 0) Vjv6d&Q  
     sdg2^]|  
End Function q%e'WMG~n  
-5+Yz9pv[  
Private Function WriteBytes(ByVal ByteCount As Long, ByRef DataBytes() As Byte) As Boolean v9-4yZU^WR  
'//write data from array }Le]qoW['  
    Dim RetVal As Long H.4ISmXU  
    Dim BytesToWrite As Long xh$yXP0/  
    Dim BytesWritten As Long JJ ?'<)EF  
     2=n `z) R  
    RetVal = WriteFile(hDisk, DataBytes(0), ByteCount, BytesWritten, 0) W/xPVmnV  
     7=^}{  
    WriteBytes = Not (RetVal = 0) 1h?ve,$  
End Function Yq6 @R|u  
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
92楼  发表于: 2015-09-06   
这才是我当年写出的一个比较烂的程序 $V!.z%Vgf  
*)-@'{]uB  
Main2.bas FEu" b@v  
/~w*)e)  
Attribute VB_Name = "SubMain" LdG?kbJ&y  
Option Explicit ||QK)$"  
3kC|y[.&  
'采集文件与临时文件 XZARy:+bc  
Public Const TmpFile As String = "d:\30-0600.dat" ~LpkA`Hn!  
'已有数据:30-0600.dat /30日早6点进车与6:30出车头 /X.zt `  
zHZfp_I  
Public fStatus As Long, hFile As Long, bytesRW As Long, lptrFile As Long UHvA43  
Public hBCFile As Long  '记录采集参数的文件 4tLdqs  
Public Const TmpBMP As String = "d:\1.bmp" V<S6 a  
Public hTmpFile As Long 7)jN:+4N  
4~h 0/H"  
^C ~Ryw7  
'采集窗口参数常量 ~S Bb2*ID  
Public Const FrameH As Long = 280& F+(S-Qk1  
Public Const FrameW As Long = 768& +5*bU1}O  
Public Const pFrameSize As Long = FrameW * FrameH 9 ;p5z[jI  
ZAn @NA=  
'标志区范围,用于识别车辆 \ opM}qZ  
Public Const PilarC As Integer = 260   '识别标志立柱中线坐标X S,6/X.QBv  
Public Const mkW As Integer = 28  '识别标志立柱宽度 7WS$fUBi  
Public Const mkH As Integer = 80 ''识别标志立柱高度(上白中黑下白) TG$ #aX\'  
Public Const mkY As Integer = 4 ''识别标志立柱Y坐标(40-79白, 80-119黑,120-159白) 5tpC$4m  
Public Const mkX As Integer = PilarC - mkW / 2 '识别标志立柱X坐标 re[5lFQ~Z  
'车缝检测位置常数  yP+<kv4  
Public Const sSize As Long = 32& 'hU5]}=  
Public Const sPos As Long = 310& E-.X%xfO  
Public Const sPosL As Long = 200& ^rO"U[To  
Public Const sPosR As Long = 500& 5H XF3  
'车缝检测框位置 -o%? ]S  
Public Slice(1 To sSize, 1 To FrameH) As Byte G`O*AQ}[  
Public SliceL(1 To sSize, 1 To FrameH) As Byte 6c-3+,Y"#  
Public SliceR(1 To sSize, 1 To FrameH) As Byte n]$rLm%^  
Public avSL As Integer, avSLR As Integer, avSLL As Integer >P~*@>e  
s0 ;a j<J  
?8H{AuLB  
Public MKpilar(1 To mkW * mkH) As Byte   '一维数组用于亮度对比度分析,比使用二维数组更便于VB编译优化 0H>gMXWE]  
'该数组用于亮度对比度调节、车辆通过识别与车皮间隔识别 `i cs2po  
Public BsLine(1 To 4 * FrameW) As Byte, bsAV As Integer  '图像的前4行。用于确定标志区的亮度与对比度范围 lr~ |=}^  
Public PilarW As Long, PilarH As Long, PilarX As Long, PilarY As Long 1gkpK`u(B  
Public LeftBK(1 To 1024, 0 To 1) As Byte, RightBK(1 To 1024, 0 To 1) As Byte XH~(=^/_  
'前后帧左右上角128列*8行像素块,根据平均值差绝对值判断进车方向 4x[_lsj   
E qz|eS*6  
7:?\1 a  
yjL+1_"B  
'一次连续采集的帧数 ]VKQm(,0  
Public tFrames As Long AaA!U!B  
R)JH D7 1  
'在采集卡申请的缓存中,是按帧为单位的,每一帧包含奇偶场两场的数据 Gm:s;w-;v  
'而该卡的硬件设置是按场采集,只需要读第一场的数据即可。 Hq:: F ?  
'所以要设置的缓存帧的大小是frameW*frameH*2,而一场的数据量为pFrameSize U52 V1b  
er7(Wph  
Public pFRAME(1 To FrameW, 1 To FrameH) As Byte dV38-IfGkl  
Public pBuffer(1 To FrameW * FrameH * 2) As Byte 27Z qdHd  
Public pWorkSpace(1 To FrameW * FrameH) As Long SkmTW@v  
Public Const pBufferSize As Long = FrameW * FrameH * 2 OS@uGp=  
Public pGray(0 To 255) As Long '整幅图像的灰度直方图 Zw0KV%7hD  
O)vGIp?f't  
Public hBoard As Long   '采集卡标识 dB6 ,pY(  
Public mBufferAddr As Long  '缓存地址  d=^QK{8  
Public BufferSize As Long  '缓存大小(字节) R&.&x'<  
Public iCurrentCard As Long ;K\2/"$QD  
Public CapStatus As Long T.;{f{  
Public iFrames As Long 4;Ucas6  
Public currentBr As Byte, currentContr As Byte yPtE5"(o  
{Z8GG  
Public hMEM As Long, mStatus As Long TYGI f4z  
Public Const hMemSize As Long = pFrameSize * 4 XN U w  
Public hMemWork As Long /}~=)QHH  
Public Const hMemWorkSize As Long = pFrameSize * 5 /i>n1>~yn  
-fFtHw:kHh  
3W[?D8yi)  
'[liZCg  
'串口接收轨道衡数据 A_S7z*T  
Public WeightFromCom As String a)pc+w#  
Public bReceiveComplete As Boolean ? s$d("~  
07:V[@'  
/Z:NoTGn  
Public Type GrayBMPHeader -V6caVlg  
  Tag As Integer L5x;# \#p  
  FileLength As Long    '文件大小 w6!97x  
  Reserve1 As Long EQ~<NzRp=  
  DataOffset As Long    '图像数据偏移量 E8r6P:5d`  
  BMPHeaderSize As Long  '文件头长 6H'A]0  
                        'length of the bitmap info header used to describe the bitmap colors, compression,… K0j%\]\Tp  
                        'the following sizes are possible: "NA<^2W@J  
                        '28h - windows 3.1x, 95, nt, … z8t;jw  
                        '0ch - os/2 1.x wW*7  
                        'f0h - os/2 2.x JK< []>O  
pZ|{p{_j  
  ImageWidth As Long           '图像宽(像素数) rHw#<oV  
  ImageHeight As Long          '图像高(像素数) *w4#D:g  
  PlaneNumber As Integer  '图像层数 xtP:Q9!N  
  bpp As Integer    'bits per pixels    '1 - monochrome bitmap 46D`h!7L  
                                        '4 - 16 color bitmap k*N!U[]  
                                        '8 - 256 color bitmap ' 4i8&p`/  
                                        '16 - 16bit (high color) bitmap n46!H0mJ  
                                        '24 - 24bit (true color) bitmap i;9X_?QF  
                                        '32 - 32bit (true color) bitmap P*iC#w]m  
  Compression As Long '压缩方法     '0 - none (also identified by bi_rgb) <L4$f(2  
                                    '1 - rle 8-bit / pixel (also identified by bi_rle4) xA7~"q&u  
                                    '2 - rle 4-bit / pixel (also identified by bi_rle8) 5e,u*J]  
                                    '3 - bitfields (also identified by bi_bitfields) PF /K&&9}  
  IMAGESIZE As Long  '图像数据字节数 MF<ZB_@  
  hResolution  As Long  '水平分辩率  像素数/米 v2rO>NY4  
  vResolution  As Long  '垂直分辩率 D(']k?  
  ColorsinBMP As Long   '图中所用的颜色。对256色图像总为0x100 (J5} 1Q<K  
  ImportantColors As Long <{k{Coy  
  Pallate(0 To 255) As Long  '图像每个值对应的实际显示颜色,项数对应PallateNumber所指调色板项数 *:xOenI  
End Type E5rV}>(Y  
Vu.=,G  
|D-[M_T5  
YT+b{   
Public BMPHeader As GrayBMPHeader, BMP1 As GrayBMPHeader )S+fc=  
Public sRECT As RECT )TiM>{  
ph5{i2U0  
Og%Y._  
Public conn As ADODB.Connection b_nE4>  
Public rsTrain As ADODB.Recordset 1!.-/  
Public rsOperater As ADODB.Recordset i%.NP;Qq]M  
Public rsGoods As ADODB.Recordset $L0sBW&  
Public rsGood2 As ADODB.Recordset 1qNO$M  
Public rsSender As ADODB.Recordset aBReIK o  
Public rsReceover As ADODB.Recordset q{9 \hEeb  
Public rsTrainTMP As ADODB.Recordset tE=09J%z  
q( ~rk  
EB!ne)X  
'打开采集卡 [nig^8  
'设置参数 xD&n'M]  
'设置为实时单帧采集到缓存方式 e,}h^^"  
'由另一线程查询采集状态,如果完成采集,传送至用户数组分析或保存 9.\SeJ8c  
kHhp;<  
1xS+r)_n@  
Sub Main() #'1dCh vZ  
  Dim i As Integer, status As Long Z C01MDIY  
     ;: _K,FU  
   InitBMPinfo #&kj>   
   '生成BMP文件头---该文件头是固定将pFRAME数组写成BMP文件 TSewq4`K  
    BMPHeader.Tag = &H4D42 ;@qS#7SRB  
    BMPHeader.ImageWidth = FrameW xkRMg2X.>9  
    BMPHeader.ImageHeight = FrameH I9G^T' W  
    BMPHeader.BMPHeaderSize = &H28 J78.-J5 j0  
    BMPHeader.PlaneNumber = 1 \:{K",2  
    BMPHeader.bpp = 8 Wj,s/Yr:  
    BMPHeader.Compression = 0 2 G_KTYJ  
    BMPHeader.hResolution = &H1274   'Windows pBrush.exe的默认值,PhotoED.exe默值为0 uT, i&  
    BMPHeader.vResolution = &H1274 d]s^?=gM  
    BMPHeader.ColorsinBMP = 256 B@M9oNWHu  
    BMPHeader.ImportantColors = BMPHeader.ColorsinBMP C`_/aR6  
    BMPHeader.DataOffset = Len(BMPHeader) ~) _N h  
    For i = 0 To 255 yR|2><A  
      BMPHeader.Pallate(i) = RGB(i, i, i) 2k<#e2  
    Next i b/a\{  
    BMPHeader.IMAGESIZE = FrameH * FrameW 5GScqY,aB  
    BMPHeader.FileLength = Len(BMPHeader) + BMPHeader.IMAGESIZE *tj(,:!  
;dUKFdKH}  
n?cC]k;P~  
    MoveMemory BMP1, BMPHeader, Len(BMPHeader) V4jMx[   
     Ed u(dZbKg  
    BMP1.ImageWidth = FrameW bC:sd2s  
    BMP1.ImageHeight = FrameH * 2 _N|%i J5  
    BMP1.IMAGESIZE = BMP1.ImageWidth * BMP1.ImageHeight sPZwA0%  
    BMP1.FileLength = Len(BMP1) + BMP1.IMAGESIZE Z S=H1  
#< [&Lw  
  '确定标志位置,为pilarX, pilarY确定初始值 Hj r'C?[  
   PilarW = mkW $]_SPu  
   PilarH = mkH  '此两项为固定值 BM?!?  
   PilarX = GetSetting(App.EXEName, "Mark", "MarkX", mkX) 7P3pjgh  
   PilarY = GetSetting(App.EXEName, "Mark", "MarkY", mkY)  '此两项需要在程序初始化时检查并进行调整 `$JvWN,kB  
   #T8o+tv  
   EP@u4F  
  '连续采集记录文件 &P9fM-]b s  
  ' 建立一个缓冲区为页对齐方式的文件 KX9IC 5pR  
  If Dir(TmpFile) <> "" Then ZT!8h$SE:  
    hFile = CreateFile(TmpFile, GENERIC_READ Or GENERIC_WRITE, _ $Ah p4oiE  
     0&, 0&, OPEN_ALWAYS, FILE_FLAG_NO_BUFFERING, 0&) j H2)8~P  
    ' 在95/98中,如果打开文件时没有声明overlapped方式,在读定文件时就不能使用overlapped参数项 :l o5,B;k  
    ' 而必须用setfilepointer函数调节与操作系统保留的文件指针。 &Iy5@8  
  Else P _fCb  
    hFile = CreateFile(TmpFile, GENERIC_READ Or GENERIC_WRITE, _ N8Rq7i3F?a  
     0&, 0&, CREATE_ALWAYS, FILE_FLAG_NO_BUFFERING, 0&) s9sl*1n1m`  
  End If rZdOU?U  
  If hFile = 0 Then bT 42G [x  
    MsgBox TmpFile & ": File Open Error", vbOKOnly |#o' =whTl  
    Exit Sub 5]I)qij q  
  End If {H[N|\  
  '采集参数记录文件 }UsH#!9.  
hBCFile = FreeFile() lfDd%.:q4S  
Open TmpFile + ".BC" For Binary Access Read Write As #hBCFile Ygk_gBRiC  
   M^oL.'  
hMEM = VirtualAlloc(ByVal 0&, hMemSize, MEM_COMMIT, PAGE_READWRITE)  ’分配系统内容 F_:zR,P%#  
If hMEM = 0 Then 6vbKKn`ST  
    fStatus = GetLastError <$-^^b(y  
    MsgBox "内存分配错误: 错误代码 - " & Str(fStatus) & vbCrLf _ (n7xYGfYS  
     & "请向技术人员报告该错误代码。", vbOKOnly ~{lb`M^]h  
    CloseHandle hFile N 5Om~D  
    Exit Sub * :TwO=)  
End If EF:ec9 .  
btEyvqs~X  
hMemWork = VirtualAlloc(ByVal 0&, hMemWorkSize, MEM_COMMIT, PAGE_READWRITE) ;]1t| td8  
If hMemWork = 0 Then M}[Q2v\  
    fStatus = GetLastError <rgK}&q  
    MsgBox "内存分配错误: 错误代码 - " & Str(fStatus) & vbCrLf _ }nPt[77U_7  
     & "请向技术人员报告该错误代码。", vbOKOnly 6 agG*x  
     '释放已成功分配的内存 d)-ZL*o  
    mStatus = VirtualFree(ByVal hMEM, hMemSize, MEM_DECOMMIT) + GQ{{B  
    mStatus = VirtualFree(ByVal hMEM, 0&, MEM_RELEASE) 36OQHv;&  
     z[J=WI  
    CloseHandle hFile ?:9y !Q=  
    Exit Sub xK_UkB-$i  
End If vVo'f|fW  
V WZpEi  
' Test writing 9k71h`5  
'WriteFile hFile, ByVal hMEM, ByVal 4096&, bytesRW, ByVal 0& ^AU-hVj  
     gq+0t  
   '初始化采集卡参数 [ K/l;Zd  
   iCurrentCard = -1 b>p_w%d[[J  
   hBoard = okOpenBoard(iCurrentCard) T2Z$*;,>T  
   Debug.Print hBoard lfM vNv  
   If hBoard = 0 Then ,V 52Fj  
      ExitGrabber 1 jB0gNe  
      End N}U+K  
   End If u|}\Af  
   okGetBufferSize hBoard, mBufferAddr, BufferSize VC/n}7p  
   If mBufferAddr = 0 Then 0'*{BAWx  
     MsgBox "缓存不存在!" GYQ:G=  
     ExitGrabber m   uO.  
   End If  of*T,MUI  
   Debug.Print Hex(mBufferAddr), Hex(BufferSize) #1$4<o#M  
   5B:"$vC{=  
   g^A^@~M  
   currentBr = 128: currentContr = 128 #sCR}  
   '设置视频输入参数 / Q@4HV  
   okSetVideoParam hBoard, VIDEO_SOURCECHAN, 1 'Video2 K Ha,6X  
      ' lParam=0,1.. Comp.Video; 0x100,101...to Y/C(S-Video), 0x200,0x201 to RGB Chan.Input w~Q\:<x&~Z  
   okSetVideoParam hBoard, VIDEO_BRIGHTNESS, currentBr '亮度  DlCN  
   okSetVideoParam hBoard, VIDEO_CONTRAST, currentContr '对比度  ---初始设置条件下如果图像亮度达不到基本要求则控制灯光 R4;1LZ8XzS  
   okSetVideoParam hBoard, VIDEO_RGBFORMAT, FORM_GRAY8 '8位灰度模式 DDkN3\w  
   okSetVideoParam hBoard, VIDEO_TVSTANDARD, 0 'PAL制式 +I5\ `By=  
   okSetVideoParam hBoard, VIDEO_SIGNALTYPE, &H10000 '逐行(低字)同步开槽(高字) +3. 9)w  
   okSetVideoParam hBoard, VIDEO_RECTSHIFT, 144 + &H2C0000 '有效区起始位置:高字Y偏移,低字X偏移 (144/44经验值) heIys.p  
   okSetVideoParam hBoard, VIDEO_AVAILRECTSIZE, FrameW + FrameH * 2 * &H10000 '有效区大小:低字X高字Y (768/576采集卡最大值) QDYuJ&!h  
   okSetVideoParam hBoard, VIDEO_FREQSEG, 0 ' 低频部分信号 :a)RMp+^0  
   YQ:$m5ai  
   '设置采集参数 l[[`-f8j  
   okSetCaptureParam hBoard, CAPTURE_INTERVAL, 0  '逐帧 @uyQH c,V  
   okSetCaptureParam hBoard, CAPTURE_CLIPMODE, 2 '裁剪方式 %!Eh9C *  
   okSetCaptureParam hBoard, CAPTURE_BUFRGBFORMAT, FORM_GRAY8  '8位灰度 :MF`q.:X  
   okSetCaptureParam hBoard, CAPTURE_HARDMIRROR, 0 '不作镜像变换 aMe &4Q  
   okSetCaptureParam hBoard, CAPTURE_FRMRGBFORMAT, FORM_GRAY8 '帧存格式 a({Rb?b  
   okSetCaptureParam hBoard, CAPTURE_SAMPLEFIELD, 0 ' 逐场采集 xL_ QTj  
   okSetCaptureParam hBoard, CAPTURE_HORZPIXELS, 944  '水平像素数 PAL制式固定值  &_Cc  
   okSetCaptureParam hBoard, CAPTURE_VERTLINES, 625 '垂直线数 kIS )*_  
   okSetCaptureParam hBoard, CAPTURE_SEQCAPWAIT, 0 '不等结束立即返回 ."dT6uE  
   'okSetCaptureParam hBoard, CAPTURE_BUFBLOCKSIZE, FrameW + FrameH * 2 * &H10000 iWjNK"W  
   'Buffer Block Size不用设置,而用okSetTargetRect函数进行动态调节 9U<WR*H  
   5(CInl  
   >mA]2gV<a  
   okCloseBoard hBoard Ag0w8F  
   Sleep 50 BEb?jRMjLg  
   hBoard = okOpenBoard(iCurrentCard)   '关闭后重新打开使新的设置值生效 #\X)|p2  
   YM;ro5_KF  
   '设置数据传送方式 Awfd0L;9  
   'okSetConvertParam hBoard, CONVERT_FIELDEXTEND, FIELD_COPYEXTEND '逐行并扩展行 -S]ercar  
   '该设置对本程序无意义,因为程序直接用CopyMemory方法读缓存,而扩展行方式是在用采集卡内置函数读RECT过程中实现的。 %52e^,//  
   @Un/,-ck  
   sRECT.Right = -1   '用于获得当前设置值 A nl1+  
   iFrames = okSetTargetRect(hBoard, BUFFER, sRECT) X~VI}dJ  
   Debug.Print sRECT.Left, sRECT.Right, sRECT.Top, sRECT.Bottom [/hoNCH!  
   Debug.Print okSetCaptureParam(hBoard, CAPTURE_BUFBLOCKSIZE, -1)  'FrameW + FrameH * &H10000 axC{azo|  
   sRECT.Left = 0 PH%t#a!j3/  
   sRECT.Top = 0 Ld_uMe?Z  
   sRECT.Right = sRECT.Left + FrameW }\<=B%{  
   sRECT.Bottom = sRECT.Top + FrameH * 2 p9i7<X2&  
   iFrames = okSetTargetRect(hBoard, BUFFER, sRECT) 19GF%+L ,  
   x/{-U05  
   sRECT.Right = -1   '检查新设置值 6 DQOar>d  
   iFrames = okSetTargetRect(hBoard, BUFFER, sRECT) sT1 OAK\^  
   Debug.Print sRECT.Left, sRECT.Right, sRECT.Top, sRECT.Bottom ^jL)<y4`  
   Debug.Print Hex(okSetCaptureParam(hBoard, CAPTURE_BUFBLOCKSIZE, -1)) 4qDO(YWf  
   Zex~ $r  
   If TESTSignal = False Then -<x%  
      'ExitGrabber +$ djX=3  
   End If I \1E=6"  
   YC%x W*  
   *<cRQfA1  
   ]p+KN>1e  
   '设为实时采集状态 &J/!D#  
   'iFrames = okCaptureActive(hBoard, BUFFER, 0&) 4ZUtK/i+r  
   gHp4q!SJ7  
   oO[eer_S-  
   '单帧采集 "Fmq$.$%  
   'okWaitSignalEvent hBoard, EVENT_FRAMEHEADER, -1 tBzE(vW  
   'iFrames = okCaptureSingle(hBoard, BUFFER, 0&) GtmoFSZ  
   okCaptureTo hBoard, BUFFER, 0, 1 'single _"Y7}A\9  
   'Do While okGetCaptureStatus(hBoard, False) <> 0 JQbaD-  
   '   Sleep 20 `/m] K ~~  
   'Loop QyTN  V  
   okGetCaptureStatus hBoard, True -]KgLgJ  
   MoveMemory pFRAME(1, 1), ByVal mBufferAddr, pFrameSize dY$nw  
   '写入768*576测试图象 PYi<iSr  
   ArrayToBMP TmpBMP ? 3DFm  
   >yn?@ve@  
   '打开数据库 t9<BQg  
   Set conn = New ADODB.Connection OcF_x/#  
   conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ m %+'St|qr  
      "Persist Security Info=False;Data Source=" & "c:\train\train.mdb" & _ HHw&BNQG  
      "; Mode=Read|Write" 2UYtEJ(?`{  
   conn.Open j^#\k m B  
   {nSgiqd"28  
   frmRecord.Picture1.Picture = LoadPicture(TmpBMP) V$ DB4YM1k  
   frmRecord.Visible = True WVQHb3Pe0  
   frmQuery.Visible = True  Yf[Cmn  
   Load frmReceiveFromComm do^=Oq07$  
   A ,0}bFK  
   '调试参数 uHquJQ4  
   If InStr(UCase(Command()), "/CAPTURE") > 0 Then JQ}4{k  
     SignalBox.Visible = True %fld<O  
   End If >,zU=I?9Y  
   If InStr(UCase(Command()), "/COMM") > 0 Then tlO=>  
     frmReceiveFromComm.Visible = True :fRta[  
   End If k2->Z);X  
k"[AV2UW1  
End Sub t5l<Lm)  
,DHH5sDCn  
Sub ExitGrabber() 8?L-3/  
  '关闭数据库 5);"()g32  
  '关闭采集卡 zhow\l2t}  
  mStatus = VirtualFree(ByVal hMEM, hMemSize, MEM_DECOMMIT) h-(NWxK+  
  mStatus = VirtualFree(ByVal hMEM, 0&, MEM_RELEASE) 1H">Rb30@  
  mStatus = VirtualFree(ByVal hMemWork, hMemWorkSize, MEM_DECOMMIT) ]GRVU  
  mStatus = VirtualFree(ByVal hMemWork, 0&, MEM_RELEASE) o AN,_1v)  
  okStopCapture hBoard vRaxB  
  okCloseBoard hBoard kS{k=V&hf_  
  CloseHandle hFile ozS'n]8*  
  Close #hBCFile $U ._4  
  conn.Close FiRe b3zR  
  End E5S(1Z}]p{  
End Sub a m5;B`}q  
.DwiIr'  
Function ArrayToBMP(ByVal File As String) @+~URIG)  
Dim BytesWrite As Long i88 5T '  
H{E(=S  
hTmpFile = CreateFile(File, GENERIC_READ Or GENERIC_WRITE, 0&, 0&, _ `@\FpV[|P  
  CREATE_ALWAYS, 0&, 0&) ^0_>  
PQ!'<  
If hTmpFile = 0 Then !4^Lv{1QZ  
   ArrayToBMP = False A#q.)8  
   Exit Function =1>G * ,  
End If ql.[Uq  
s +S6'g--  
SetFilePointer hTmpFile, 0&, 0&, FILE_BEGIN bp8sZK"z  
WriteFile hTmpFile, BMPHeader, 2&, BytesWrite, ByVal 0& M3KK^YRN  
SetFilePointer hTmpFile, 2&, 0&, FILE_BEGIN of7'?]w  
WriteFile hTmpFile, BMPHeader.FileLength, Len(BMPHeader) - 2, BytesWrite, ByVal 0& Da! fwth  
' $yy  
SetFilePointer hTmpFile, Len(BMPHeader), 0&, FILE_BEGIN ^K[xVB(&  
WriteFile hTmpFile, pFRAME(1, 1), pFrameSize, BytesWrite, ByVal 0& ~^Al#@  
FDiDHOR  
If BytesWrite < pFrameSize Then K;THYMp/[  
  ArrayToBMP = False 5R.jhYAj  
End If u$nmnd`g  
W1o6Sh8v(  
CloseHandle hTmpFile G1X73qoHT<  
OFv-bb*YZ  
End Function H]V(qq{  
K ..Pn 17t  
Function ArrayToBMP1(ByVal File As String) yWc%z6dXC  
\g]rOYW  
Dim BytesWrite As Long 'Eia=@  
~<IQe-Q 5  
hTmpFile = CreateFile(File, GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0&, _ ffB<qf)?G  
  CREATE_ALWAYS, 0&, 0&) 0"@J*e#  
r.LOj6c  
If hTmpFile = 0 Then 56c3tgVF  
   ArrayToBMP1 = False b[&ri:AC  
   Exit Function {1UU `d  
End If - ]We|{  
7dB_q}<  
SetFilePointer hTmpFile, 0&, 0&, FILE_BEGIN M4 ?>x[Pw  
WriteFile hTmpFile, BMP1, 2&, BytesWrite, ByVal 0& _,F\%}  
WB (?6"  
SetFilePointer hTmpFile, 2&, 0&, FILE_BEGIN #.]W>h N8\  
WriteFile hTmpFile, BMP1.FileLength, Len(BMP1) - 2, BytesWrite, ByVal 0& b-`P-  
WM$Z?CN%KB  
SetFilePointer hTmpFile, Len(BMP1), 0&, FILE_BEGIN "9c!p  
WriteFile hTmpFile, pBuffer(1), pBufferSize, BytesWrite, ByVal 0& -1d$ w`  
n~>b }DY  
If BytesWrite < pBufferSize Then 5' t9/8i  
  ArrayToBMP1 = False k%-y \WM  
End If 9nO&d(r g  
t,w/L*r+w  
CloseHandle hTmpFile wuCZz{c7  
mOjjw_3gq  
End Function !f!YMpN  
'q/C: Yo  
'使用该过程建立的文件要求在用后关闭 &j'k9C 2p  
Public Function ArrayToBMP2(File As String) As Boolean b+AxTe("  
~tNk\Kkv  
Dim BytesWrite As Long N- }OmcO]e  
#EKnjh=Uq  
ArrayToBMP2 = True =<M>fJ )  
@/01MBs;  
hTmpFile = CreateFile(File, GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0&, _ rmX5-k  
  CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, 0&) bjj F{T  
g-x;a0MQx  
If hTmpFile = 0 Then 4,)QV_?  
   ArrayToBMP2 = False +=L+35M  
   Exit Function C2iOF/4  
End If #"C* dNAB  
RM%Z"pc Y6  
SetFilePointer hTmpFile, 0&, 0&, FILE_BEGIN jtpk5 fJB  
WriteFile hTmpFile, BMPHeader, 2, BytesWrite, ByVal 0& o+^e+ptc  
kiin78W  
SetFilePointer hTmpFile, 2&, 0&, FILE_BEGIN %0815 5M  
WriteFile hTmpFile, BMPHeader.FileLength, Len(BMPHeader) - 2, BytesWrite, ByVal 0& l)KN5V  
2l+'p[b0>  
SetFilePointer hTmpFile, Len(BMPHeader), 0&, FILE_BEGIN N1n\tA?  
WriteFile hTmpFile, pFRAME(1, 1), pFrameSize, BytesWrite, ByVal 0& 3uvl'1(%J  
K;`*n7=IA  
If BytesWrite < pFrameSize Then Pa; *%7  
  ArrayToBMP2 = False 7 oYD;li$k  
End If w3fD6$  
`x L@%  
CloseHandle hTmpFile (/> yfL]J  
"$"<AKCwS  
End Function )zP"Uuu  
LBpAR|  
Private Function TESTSignal() As Boolean P4MP`A  
Dim extsign As Long, videotype As Long, scanlines As Long, fieldfrq As Long F')E)tV  
guy!/zQ>A  
extsign = okGetSignalParam(hBoard, SIGNAL_VIDEOEXIST) 8z&/{:Z@pH  
EO",|V-  
If extsign = 1 Then Vhm^<I-d  
   TESTSignal = True '/ueY#eG  
Else u91  
    If extsign = 0 Then v<0S@9~  
        MsgBox "无视频输入信号,检查摄像机电源!", vbOKOnly |CS&H2!s  
        TESTSignal = False BNJG-b|g^  
        Exit Function u0uz~ s  
    End If 03 v\v9<T  
End If D* HK[_5  
`Sj8IxO  
'测试视频输入类型 8,CL>*A  
'video type @X/-p3729  
okWaitSignalEvent hBoard, EVENT_ODDFIELD, 40 k]TJL9Q  
videotype = okGetSignalParam(hBoard, SIGNAL_VIDEOTYPE) &t@ $]m(  
If videotype = 1 Then OWN|W,  
        '"隔行信号(Interlaced)" hL;??h,!_  
Else jNIz:_c-~  
   If videotype = 0 Then A}"uEk(R  
       '"逐行信号(Non-interlaced)" i-k(/Y0  
   Else ?K.!^G  
     If videotype = -1 Then k'[\r>T  
       ' "不支持" </fTn_{2s8  
     End If <(qdxdUp  
   End If G<*h,'B  
End If ov>`MCS,v  
b]8\% =d  
'测试垂直扫描线数 )pey7-P7g5  
'video scanlines a  ?wg~|g  
scanlines = -1 .lc gM  
scanlines = okGetSignalParam(hBoard, SIGNAL_SCANLINES) 2NL|_W/  
    If scanlines = -1 Then 3fop.%(  
        ' "不支持" !wrAD"l*@  
    Else pA EJ=Te  
        'Trim(Str(ScanLines)) + " 行数/幅" Y k"yup@3  
    End If {#{nU NW  
Xn<|6u  
'测试帧频 V/"41  
'video field frequency giN(wPgYP  
    fieldfrq = okGetSignalParam(hBoard, SIGNAL_FIELDFREQ) h!hv{c  
    If fieldfrq = -1 Then uMC0XE|S  
        'lblSignal(8) = "不支持" +hWeN&A  
    Else 5'0kf7  
        'lblSignal(8) = Trim(Str(FieldFRQ)) + " 场数/秒" i)ibDrX!I  
    End If wz'in  
End Function r^\Wo7q  
O_SM!!,  
R?*-ZI[>w  
Sub PicIdentify() D>wo>,G  
'本程序完成从文件中按顺序读出一幅图像并完成图像识别 ?N%5c%oF  
'根据固定位置判断透过车皮连接处接收的对面的立柱影像。出现立柱后该帧前1-2帧与后1-2帧分别为车号信息与车皮信息 ?H!X p  
'判定标准:如果在立柱位置上有明显的模式反差,则视为车皮之间的间隔 F|W H=s3  
'方法:对立柱标志区进行平均值二值化,面积为32*40,亮区(255)与暗区(0)的亮度平均值理论差大于200倍,实际差值应不小于100倍 } 4>#s$.2  
=\<!kJ\yH  
  Dim fPTR As Long, cFrame As Long Pb :6nH=  
  Dim i As Long, j As Integer, pTotal As Long, pAV As Integer 4T<dI6I0  
     twTRw:.!f  
G~4|]^`g  
cFrame = 0 jm |zn  
{\= NZ\  
7nPm{=B G  
Do While cFrame < tFrames y+VR D  
   Lhgs|*M  
  fStatus = SetFilePointer(hFile, cFrame * pFrameSize, 0&, FILE_BEGIN) @qsOWx`l$  
  fStatus = ReadFile(hFile, ByVal hMEM, ByVal pFrameSize, bytesRW, ByVal 0&) ;Y &2G'  
  MoveMemory pFRAME(1, 1), ByVal hMEM, pFrameSize ><@& &u.  
   C4C! -12  
  frmRecord.RText.Text = Str(cFrame) JAL"On#c#0  
  frmRecord.RText.Refresh qkyYt#4E  
       JDMsco+j5  
  If CheckMark = True Then eR8>5:V_  
   ArrayToBMP TmpBMP 7aN oqS+  
   frmRecord.Picture1.Picture = LoadPicture(TmpBMP) sy9YdPPE  
   frmRecord.RText.Text = "第" & Str(cFrame) & "帧" stCFLYox  
   ]<O -  
   DrawSlice ewinG-hX_  
   lzZ=!dG  
   'i = MsgBox("检测到立柱:第" & Str(cFrame) & "帧", vbYesNo) o\y qf:V8  
   'If i = vbNo Then #+3I$ k  
   '  Exit Do jmnrpXaAx  
   'End If SR\$fmo  
   'cFrame = cFrame + 1 X`daaG_l  
   U09@pne8  
  End If [  **F  
  DoEvents `udZ =S"/L  
  cFrame = cFrame + 1 yj`xOncE}  
Loop -| t|w:&  
End Sub  PuU<  
3j$,x(ua9  
gkv,Om  
Function CheckMark(Optional iBlk As Integer = 30, Optional iWhite As Integer = 230) As Boolean v\COl*  
<gr2k8m6$  
'如标志区模式反差存在则为TRUE,否则返回FALSE 1]jUiX=T  
uFi[50  
Dim i As Integer, j As Integer, mTotal As Long, mAV As Single, mTop As Long, mBot As Long z;i4F.p  
CheckMark = True ~_SVQ7P  
   a% 82I::t  
'复制标志区 TGPHjSZ1  
For i = 1 To mkH M$LzV}k  
   MoveMemory MKpilar((i - 1) * PilarW + 1), pFRAME(PilarX, PilarY + i), PilarW &[}5yos r  
Next i q/YO5>s15  
;W#/;C _h  
For j = 1 To PilarW * PilarH / 2 Jb z>j\  
   mTop = mTop + MKpilar(j) o Bp.|8-  
Next j AzBpQb*  
T b]'  b  
For j = PilarW * PilarH / 2 + 1 To PilarW * PilarH >5]w\^QN9_  
   mBot = mBot + MKpilar(j) S4X['0rX!  
Next j o&:n>:im  
4> [tjz.?k  
mTop = mTop / PilarW / PilarH * 2 +Sdki::  
mBot = mBot / PilarW / PilarH * 2 qv+}|+aL:  
["?WVXCF8|  
mAV = (mTop + mBot) / 2 + (mBot - mTop) / 4 '标志区平均亮度 X1h*.reFAL  
a<V*  )  
'平均值极值化 kI$p~  
  For j = 1 To PilarH * PilarW $S!WW|9j.  
    MKpilar(j) = IIf(MKpilar(j) > mAV, 255, 0) qS2]|7q?Tc  
  Next j 4=n%<U`Z/  
   ~f%AbDye  
mTop = 0: mBot = 0 v&ZI<Xt+  
For j = 1 To PilarH * PilarW / 2  PYYO-Twg  
  mTop = mTop + MKpilar(j) E;x~[MA  
Next j @sb00ad2q  
d`Em) 3v  
For j = PilarH * PilarW / 2 + 1 To PilarH * PilarW ;%aWA  
  mBot = mBot + MKpilar(j) QWxl$%`89<  
Next j m-!z(vcn  
6NqLo^ "g  
! ' @  
  mTop = mTop / PilarH / PilarW * 3 2$%0~Z5  
  mBot = mBot / PilarH / PilarW * 3 7wc{.~+  
   CU(W0D  
,_t}\7  
If mBot > iWhite And mTop < iBlk Then gIXc-=Ut  
  CheckMark = True  SjO Iln  
Else 38q0iAH  
  CheckMark = False S1n 'r}z8  
End If ()i!Uo  
End Function g7W\  &  
su]ywVoRT  
Sub Capture1Frame() EC| b7  
   okCaptureTo hBoard, BUFFER, 0, 1 'single (vf5qF^  
   okGetCaptureStatus hBoard, True mkmVDRK  
   MoveMemory pFRAME(1, 1), ByVal mBufferAddr, pFrameSize \\~4$Ai[  
End Sub j2|!h%{nI  
x@>^c:-f  
6PI-"He  
Sub CopyMark(iBlk As Integer, iWhite As Integer) ?rH=<#@  
'复制标志区并返回标志区暗区与亮区的亮度平均值 cYEe`?*  
Dim i As Integer, j As Integer, mTotal As Long, mAV As Single, mTop As Long, mBot As Long, mMid As Single, bsTotal As Long a'|Dm7'4t  
   6< A3H$3b  
'复制标志区 3#T_(  
For i = 1 To mkH 6Bm2_B  
   MoveMemory MKpilar((i - 1) * PilarW + 1), pFRAME(PilarX, PilarY + i), PilarW Ti9cN)lq&  
Next i OKq={l  
-x1O|q69  
For j = 1 To mkW * mkH / 2 /2! "_?<L  
   mTotal = mTotal + MKpilar(j)  7QkAr  
Next j 6ypqnOTr  
y7s.6i}7  
iBlk = mTotal / (mkW * mkH / 2)  '标志区上部白区平均亮度 X{riI^(  
A,s .<TG  
mTotal = 0 V/-~L]G  
For j = mkW * mkH / 2 + 1 To mkW * mkH IN9o$CZ:  
   mTotal = mTotal + MKpilar(j) }tT*Ch?u  
Next j @'!61'}f  
*:A )j?(  
iWhite = mTotal / (mkW * mkH / 2) '标志区下部黑区平均亮度 {VE$i2nC8  
ETVT.R8   
'背景亮度 }UWRH.;v  
  MoveMemory BsLine(1), pFRAME(1, 1), 4 * FrameW "ae55ft//  
  For i = 1 To 4 * FrameW &9'JHF!l  
    bsTotal = bsTotal + BsLine(i) %z0@4G q  
  Next i 5{|\h}  
  bsAV = bsTotal / FrameW / 4 + nslS:(  
XUT\nN-N  
End Sub wen6"  
R OQIw  
Wh> Y_ k  
Sub AdjIMGbright(Optional bInit As Boolean = True) p^``hP:J  
p{Gg,.f!HM  
  '自动调节亮度与对比度,此时处于无车辆状态(白天特别高,而夜间特别暗) @V-CG!  
  '图像平均亮度白天不高于200(当车辆通过时可能会下降到100左右),不低于100 JZ=a3)x"  
  '            夜间不高于80(过高时通常是由于雪花噪声引起),但立柱不低于30 b511qc"i>M  
     #0WO~wL  
  Dim bsTotal As Long, i As Integer, iBlack As Integer, iBright As Integer Pjff%r^  
   VI`x fmVOQ  
  '按标准亮度与对比度采集一帧,确定背景亮度 $T0|zPK5  
  currentContr = 128   '初始对比度 T {lJ[M  
  currentBr = 128   '初始亮度 X_eV<]zA+  
  okSetVideoParam hBoard, VIDEO_BRIGHTNESS, currentBr '亮度 ]g; K_>@  
  okSetVideoParam hBoard, VIDEO_CONTRAST, currentContr '对比度 Z;mDMvIu (  
  DoEvents MPd#C*c  
  Capture1Frame |KC3^  
  '获得图像上缘4行象素 uQ.VW/>  
  MoveMemory BsLine(1), pFRAME(1, 1), 4 * FrameW Lsozl<@  
  CopyMark iBlack, iBright   '图像标志区亮度 CQ3{'"b  
  For i = 1 To 4 * FrameW MY[" zv  
    bsTotal = bsTotal + BsLine(i) @]h#T4z'  
  Next i i=<(fq  
  bsAV = bsTotal / FrameW / 4    '图像上缘基线亮度 #B)`dA0a  
   *H RxC  
  Select Case bsAV ~qT+sc!t  
     Case 0 To 60    '夜间通过灯光照明,完全没有背景  93(  
       currentBr = 150 ~dwl7Qc  
       currentContr = 60 P5P<-T{-c  
     Case 61 To 80   '有可见背景 m"vV=6m|\  
       currentBr = 140 b\\?aR |  
       currentContr = 70 :r/rByd '  
     Case 81 To 100  '有清晰背景 Va/ p   
       currentBr = 128 KXFa<^\o  
       currentContr = 80 y!^RL,HIL  
     Case 100 To 150  '有明亮背景 6dmTv9e  
       currentBr = 140                '5:30-6:00钟实测数据 ':w6 {b  
       currentContr = 50 3^us;aOr  
     Case 151 To 180 /qL&)24  
       currentBr = 130 hTn }AsfLY  
       currentContr = 60 <`9:hPp0  
     Case 181 To 220  '背景全为白色 y6?Q5x9M  
       currentBr = 110 #z t+U^#)  
       currentContr = 130 t>v']a +k  
     Case 221 To 255  '背景全为白色 \ca4X{x  
       currentBr = 100 /aJl0GL4!  
       currentContr = 100 i,,>@R  
  End Select BWX&5""  
   Dx[t?-  
  Select Case (iBlack + iBright) / 2   '图像反射光强度修正 4p~:(U[q  
        Case 100 To 150 ;@ d<*  
          currentBr = currentBr - 10 e"|9%AW@<  
        Case 151 To 255 +T^m  
          currentBr = currentBr - 20 5y"yd6O]O5  
  End Select &/, BFx"  
   I>-jKSkwc  
  okSetVideoParam hBoard, VIDEO_BRIGHTNESS, currentBr '亮度 aV(*BE/@F  
  okSetVideoParam hBoard, VIDEO_CONTRAST, currentContr '对比度 X6<HNLgra  
End Sub MOmp{@  
I/)dXk~  
Sub CopyCorner(rowID As Integer, diffL As Integer, diffR As Integer) [* > @hx  
    Dim i As Integer, j As Integer, L1 As Long, L2 As Long, R1 As Long, R2 As Long ^HL#)fK2I  
     pp[? k}@  
    For i = 1 To 8 T "G!H  
      MoveMemory LeftBK((i - 1) * 128 + 1, rowID), pFRAME(1, i), 128& I|O~F e.  
      MoveMemory RightBK((i - 1) * 128 + 1, rowID), pFRAME(640, i), 128& *qBMt[a  
    Next i .[Sv|;x"E  
     _L!" 3  
    For j = 1 To 1024 a}c(#ZLs  
      L1 = L1 + LeftBK(j, 0) LZ ID|-  
      L2 = L2 + LeftBK(j, 1) "5jZS6A]  
      R1 = R1 + RightBK(j, 0) IW1]H~1w  
      R2 = R2 + RightBK(j, 1) ESASsRzk  
    Next j +dh]k=6  
    diffL = Abs(L1 - L2) / 1024 z4J-qK~2  
    diffR = Abs(R1 - R2) / 1024 9 au)K!hN  
End Sub ?\ #4`9  
bt&vik _  
Function CheckSlice() As Boolean `?6m0|\@  
  CopySlice avSL, avSLR, avSLL x{ZVq 4  
  If Abs(avSL - avSLL) > (Abs(avSLL - avSLR) + 5) * 4 Then O.K8$  
    CheckSlice = True sq)Nn&5A  
  Else ?0;b}Xl-  
    CheckSlice = False 0 q3<RX>M%  
  End If !P92e1  
End Function ;. :UfW  
u%[*;@;9+  
Sub CopySlice(avSL As Integer, avSLR As Integer, avSLL As Integer) iy: ;g  
  Dim i As Long, j As Long, total As Long, totalL As Long, totalR As Long $~~=SOd0  
  For i = 1 To FrameH kx UGd)S  
    MoveMemory Slice(1, i), pFRAME(sPos, i), sSize m&A/IW,.  
    MoveMemory SliceL(1, i), pFRAME(sPosL, i), sSize d=4MqX r  
    MoveMemory SliceR(1, i), pFRAME(sPosR, i), sSize LL6f40hC  
  Next i -I8%  
  For i = 1 To FrameH cW GU?cv}  
    For j = 1 To sSize WD?V1:>+  
       total = total + Slice(j, i) ln=zGX.e  
       totalL = totalL + SliceL(j, i) BS|-E6E<  
       totalR = totalR + SliceR(j, i) yMSRUQ x  
    Next j oG*lU h}  
  Next i w pCS]2  
  avSL = total / FrameH / sSize eNNgxQw>m  
  avSLR = totalR / FrameH / sSize mc$c!Ax*  
  avSLL = totalL / FrameH / sSize 8w*fg6,=  
End Sub 329xo03-[  
t583Q/1@  
Sub DrawSlice() Mm[%v t40  
   frmRecord.Picture1.Line (sPosL, 0)-(sPosL + sSize, FrameH), RGB(255, 0, 0), B FUcs=7c  
   frmRecord.Picture1.Line (sPos, 0)-(sPos + sSize, FrameH), RGB(0, 255, 0), B O: BP35z_F  
   frmRecord.Picture1.Line (sPosR, 0)-(sPosR + sSize, FrameH), RGB(0, 0, 255), B ga~vQ7I_  
   frmRecord.RText.Text = Str(avSLL) & "/" & Str(avSL) & "/" & Str(avSLR) G+g`=7  
End Sub ;Ok11wOw  
Sub DrawMark(pic As Control) mifYk>J^9  
   Dim i As Long, j As Long DU7Ki6  
   pic.Line (PilarX, FrameH - PilarY)-(PilarX + PilarW, FrameH - PilarY - PilarH / 2), RGB(255, 0, 0), B n'h )(^  
   pic.Line (PilarX, FrameH - PilarY - PilarH / 2 - 1)-(PilarX + PilarW, FrameH - PilarY - PilarH), RGB(0, 0, 255), B X7 Za Q .  
   For i = 1 To PilarH \iE'E  
     For j = 1 To PilarW 6|dUz*Pr|\  
       pic.PSet (PilarX + PilarW + 10 + j, FrameH - PilarY - i), RGB(MKpilar((i - 1) * PilarW + j), 0, 0) [X~X?By>  
     Next j tt[_+e\4  
   Next i <0LB]zDWe6  
End Sub x.r`(  
y=j[v},4  
Function avIMG() As Integer -=sxbs.aA  
  Dim i As Long, j As Long, totalIMG As Long 9vj:=,TNu  
  MoveMemory pBuffer(1), pFRAME(1, 1), pFrameSize m9B3]H  
  For i = 1 To pFrameSize *r% mqAx(  
    totalIMG = totalIMG + pBuffer(i) 4*9Dh  
  Next i mmKrmM*1  
  avIMG = totalIMG / pFrameSize g<dCUIbcQ  
End Function iN {TTy  
sw@ 2 ?+  
Function avRegion(barCol As Integer, barWidth As Integer) As Integer ytC{E_  
  Dim i As Long, j As Long, totalIMG As Long r?+u}uH  
  For i = 1 To FrameH IkZ_N#m  
     MoveMemory pBuffer((i - 1) * barWidth + 1), pFRAME(barCol, i), barWidth PvB?57wkF  
  Next i ~fUSmc  
  For i = 1 To FrameH * barWidth YJ6vyG>%C  
    totalIMG = totalIMG + pBuffer(i) i ('EBO  
  Next i p4AXQuOP  
  avRegion = totalIMG / pFrameSize a "1$z`ln  
End Function RU >vnDaC  
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
93楼  发表于: 2015-09-06   

一共这么多文件。 gdZVc9 _  
i;xMf5Jz  
这是我用VB写出的最大的程序,也是用API最多的。
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
94楼  发表于: 2015-09-06   
拍下的火车 Jqj6L993e  
第6车皮 5q#|sVT7R  

/t^lI%&  
Y_B 4s-  
第9车皮 k$ M4NF~$  
Q(IS=  
  
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
95楼  发表于: 2015-09-06   

从这里里分离出来的。
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
96楼  发表于: 2015-09-06   

a0.3$  
mX?{2[  
这个地方现在已经变化很大了。以前紧靠山东农科院的实验田
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
97楼  发表于: 2015-09-06   
下一次练手,也是VB,不过只是用CCD测量济钢中板车间轧机出来的板的宽度。 @<=#i  
K-C,+ eI  
这一次,我自己做了一个二进制的尺子,用CCD在一个盒子里读尺。
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
98楼  发表于: 2021-01-02   
继续填 BotNET 或Pynthon? 有没有XDJMs接龙啊 ? #/dde9y  
B[B<U~I}  
杺栫杣杊椌柮栬,䒴蓉艿芖。
伍胥之 离线
级别: 军区司令员

显示用户信息 
99楼  发表于: 2021-07-18   
继续填个坑: 7NC8<o;  
J\$l3i/I  
用VBA控制WORD自己修订学生毕业文的格式。 I=y j  
杺栫杣杊椌柮栬,䒴蓉艿芖。
描述
快速回复

验证问题:
3 * 6 = ? 正确答案:18
按"Ctrl+Enter"直接提交