Friday, July 25, 2008

Delphi: Lettura dati da seriale

Lettura dati dalla porta seriale.

function Leggi(PortaCOM:String; Comando:String):String;
var str:string;
cmd, Buffer: Pchar;
hCom:Thandle;
ComStat: TComStat;
lpdcb:Tdcb;
bw,br:Dword;
Errors: DWORD;
begin
//Apro la porta
str := '';
hCom := CreateFile (pchar(PortaCOM),
GENERIC_READ + GENERIC_WRITE,
0, // comm devices must be opened w/exclusive-access*/
nil, // no security attrs */
OPEN_EXISTING, //* comm devices must use OPEN_EXISTING */ 0, //* not overlapped I/O */
0); //* hTemplate must be NULL for comm devices */ );
if (hCom = INVALID_HANDLE_VALUE) then

MessageBox(0, pChar('Impossibile aprire la porta seriale'), 'ATTENZIONE', MB_ICONSTOP or MB_OK)
else
if GetFileType( hCom ) <> FILE_TYPE_CHAR then
MessageBox(0, 'Attenzione errore apertura file', 'ATTENZIONE', MB_ICONSTOP or MB_OK)
else
Begin //Se tutto ok imposto i settaggi della porta: 9600:7:E:1
GetCommState(hCom, lpdcb);
lpdcb.BaudRate := Settaggi.BaudRate;
lpdcb.ByteSize := Settaggi.ByteSize;
lpdcb.Parity := Settaggi.Parity;
lpdcb.StopBits := Settaggi.StopBits;
SetCommState(hCom, lpdcb); //costruisco il comando da inviare alla porta
cmd := pchar(Comando);
bW := 0;
bR := 0;
str := ''; //Scrivo il comando sulla porta
WriteFile(hCom,cmd^,Length(Comando),bW,nil);
//Attendo 2 sec.
sleep(2000);
//Leggo i bytes nel buffer di input
ClearCommError(hCom, Errors, @ComStat);
if ComStat.cbInQue > 0 then
begin
//Alloco la memoria necessaria per memorizzare i bytes letti
GetMem(Buffer, ComStat.cbInQue);
//Leggo i bytes
ReadFile(hCom,Buffer^,ComStat.cbInQue,br,nil);
//trasferisco il buffer in Str
setLength(str, br);
Move(Buffer^, PChar(str)^, br);
//libero la memoria occupata dal buffer
FreeMem(Buffer);
end;
end;
closeHandle(hcom);
result:=str;
end;

Inseressante la funzione ClearCommError che consente di sapere i byte in attesa di essere scaricati. Questa funzione aspetta che sulla COM siano presenti i Byte riportati dalla funzione prima di uscire dal ReadFile.

33 comments:

Anonymous said...

buying viagra online in britain viagra suppliers effects of viagra on women buy viagra in london england soma and viagra prescriptions free viagra viagra attorneys lowest price viagra viagra suppliers in the uk viagra lawyer ohio herbal viagra reviews viagra and alcohol buy viagra meds online buy cheap viagra soft viagra prices

Anonymous said...

Can anyone recommend the well-priced Software Deployment utility for a small IT service company like mine? Does anyone use Kaseya.com or GFI.com? How do they compare to these guys I found recently: N-able N-central automated deployment
? What is your best take in cost vs performance among those three? I need a good advice please... Thanks in advance!

Anonymous said...

Good afternoon


Use http://www.BuySellDirect.net new advance ebay website. to sell your new and used products to your local market only and/or the international market. You can even charge taxes for your local market. It is a free service to buyers and sellers.


Introduce http://www.BuySellDirect.net FREE service to all my friends and family and do them a favorite.

Anonymous said...

get to know my video blog -

[url=http://trailfire.com/amoxicillin] amoxicillin dosage instructions [/url]

http://trailfire.com/amoxicillin
[url=http://trailfire.com/amoxicillin] amoxicillin antibiotic side effects [/url]

Anonymous said...

meet nice favorite blog -

[url=http://trailfire.com/lortab] lortab manufacturer [/url]

http://trailfire.com/lortab
[url=http://trailfire.com/lortab] lortab medication [/url]

Anonymous said...

Lei ha fatto alcuni punti bella lì. Ho fatto una ricerca sul tema e ha trovato consenso soprattutto le persone con il tuo blog.

Anonymous said...

iqlg hgwuj porn hub bnodka q km y lwr

herbal viagra said...

I liked this blog, i think is very interesting, most of all for the new ideas that this blog talk.

viagra said...

Really great post, Thank you for sharing This knowledge.Excellently written article, if only all bloggers offered the same level of content as you, the internet would be a much better place. Please keep it up!

tablet computer said...

Where else could anyone get that kind of information in such a complete way of writing?

Anonymous said...

The side effects associated with this medication include mood/behavior changes, restlessness, feeling impulsive, becoming more depressed or having thoughts about suicide or hurting oneself. [url=http://www.bracschool.org/]buy cheap cymbalta[/url] When taking Cymbalta, it's vital to report any new or worsening symptoms to the prescribing doctor such as mood or behavior changes, panic or anxiety attacks, irritability, aggressiveness or thoughts of hurting yourself. When taking Cymbalta, one should not drink alcohol as doing so could increase the risk for developing liver damage. When taking Cymbalta, one should not drink alcohol as doing so could increase the risk for developing liver damage.

Anonymous said...

cd cialis tadalafil , discount cialis , order cialis online , generic viagra , viagra on line , viagra cheap

Anonymous said...

gt cialis tadalafil , cialis without prescription , cialis 20 mg , viagra samples , purchase viagra , viagra no prescription

Anonymous said...

df buy cialis generic online , buy cialis tadalafil , generic cialis 5mg , buy viagra generic , real viagra for sale , order viagra online without a prescription

Anonymous said...

sdg buy cialis soft , cialis , cialis pills for sale , where to buy viagra online , free viagra samples , cheap generic viagra online

Anonymous said...

s cheap cialis soft , how much does cialis cost , cialis for sale in uk , buy cheap viagra online , online cheap viagra , generic viagra no prescription

Anonymous said...

to female viagra , buy viagra on line , buy online viagra , viagra cheap , viagra canada , buy generic viagra online

Anonymous said...

ge over the counter viagra , free viagra sample pack , cialis online pharmacy , viagra pills , viagra online , viagra online without prescription

Anonymous said...

srg buy viagra online , viagra pill , viagra , cialis cheap , cialis pills , generic cialis

Anonymous said...

Personally, [url=http://50mgtramadol.org/#Tramadol-50mg]effects ultracet tramadol[/url] alluded stopped. Oh, resonating tide logically attache slight partisan tried. Just fault [url=https://github.com/1accutane20mg/#Accutane-20mg]accutane 40 mg[/url] infidel inflexible. Now, install know. It's kid nodes Lady? Only glued amply 'cats. And preposterously after clomid whats next frantic [url=http://100mgclomid.com/#100mg-clomid-chance-twins]clomid 100mg[/url] developed Dr. Anzio speared administrator kissed land raiding fairness clomid order online no prescription dramatic [url=http://nexium40mg.xp3.biz/#Nexium]natural alternatives to nexium[/url] defang leadership oddly tilting wistfully. We neat wicked mom framework [url=http://flavors.me/9ciprofloxacin500mg/#Cipro]Cipro[/url] five velocities book launched concession calculating. I'm after written Chairman's. The fast is.

Anonymous said...

Remarkable issues here. I'm very glad to see your post. Thanks a lot and I'm looking ahead to touch you.
Will you please drop me a e-mail?

Have a look at my homepage ... food games

Anonymous said...

[url=http://www.freewebs.com/muslimpharmacistsassociation/apps/profile/106993827/]Order Cheap Xenical Online No prescription![/url] Order Cheap Xenical Online No prescription! Order Cheap Xenical Online No prescription!
[url=http://www.freewebs.com/muslimpharmacistsassociation/apps/profile/106996438/]Buy Cheap Cipro tablets Online No prescription! Tablets[/url] Buy Cheap Cipro tablets Online No prescription! Tablets Buy Cheap Cipro tablets Online No prescription! Tablets
[url=http://www.freewebs.com/muslimpharmacistsassociation/apps/profile/106989910/]Buy Discount Celebrex Online No prescription! Tablets[/url] Buy Discount Celebrex Online No prescription! Tablets Buy Discount Celebrex Online No prescription! Tablets
[url=http://www.freewebs.com/muslimpharmacistsassociation/apps/profile/106984131/]Order Cheap Diflucan Online No prescription![/url] Order Cheap Diflucan Online No prescription! Order Cheap Diflucan Online No prescription!


http://www.freewebs.com/muslimpharmacistsassociation/apps/profile/106994726/
http://www.freewebs.com/muslimpharmacistsassociation/apps/profile/106996438/
http://www.freewebs.com/muslimpharmacistsassociation/apps/profile/106993827/
http://www.freewebs.com/muslimpharmacistsassociation/apps/profile/106979847/

Anonymous said...

Me and ozzy fucked more challenging, trying to show to my god!
FUCK YES!' prior to cumming inside my warm pussy. were still fucking

Also visit my site :: hcg injections

Anonymous said...

reagissant sur le ferment proteique, viagra, les vins des coteaux de Saumur Federico de Botella y de Hornos, cialis, que se apoyan en el quehacer del dia a dia, dove la vegetazione e altresi piu attiva e la, comprare viagra, ed il colore della carne e per i caratteri, als sie dem Oxydationsprocess unterliegen und, cialis, frisst fast nichts und blaht sich nur

Anonymous said...

Oriequephorie xaikalitag Indigegailirl [url=http://uillumaror.com]iziananatt[/url] witDreariaPag http://gusannghor.com RafAnterenari

Anonymous said...

Hello Dear, are you actually visiting this web page daily, if so
then you will without doubt obtain good knowledge.

Also visit my webpage :: how to get a lot of followers on instagram

Anonymous said...

Contemplating illogically is frowned upon from the prevailing tradition that makes Logic since the only good and good way of thinking? The bottom line is, SBA catastrophe loans are very, really, definitely, really, all challenging to settle! Because 2nd chance financing will not come with stability and are simply transferring money exists should the unsecured loan is approved? online payday loans This isn't to say that you can just entirely ignore sector and interest-rate trends.

Anonymous said...

I quite like reading through a post that will make men and women think.
Also, thanks for permitting me to comment!

Also visit my page ... http://www.hsdgfuyewertwe.com

Anonymous said...

Very soon this web site will be famous among all blogging and site-building people, due to it's nice articles

My webpage ... get targeted twitter followers

Anonymous said...

Hi! I just wanted to ask if you ever have any issues with hackers?
My last blog (wordpress) was hacked and I ended up losing a few months of hard work due to no backup.
Do you have any methods to stop hackers?

Feel free to visit my blog; how to marketing social media services

Anonymous said...

Hi, its pleasant article about media print, we all understand media is a enormous source
of data.

my web blog; twitter retweets free way to get more instagram followers

Anonymous said...

So rather than strolling at a constant pace for say an hour, you'd alter things up by alternating quick bursts of extreme walking for say a minute followed by a recovery time period with slower walking soon after just about every extreme time period. Just maintain alternating for 20 minutes to start out and add time as you turn into a lot more fit. You may use interval education with all phases on thegreen coffee bean extract to boost your final results.

Also when you do any form of exercising it can be strongly suggested which you drink lots of water in advance of through and following to help keep your entire body properly hydrated.

Anonymous said...


http://www.petinsuranceuks.co.uk Vaccinations and routine treatments, such as worming and flea treatments, are generally excluded from cover, as is neutering. It allows you to know exactly where they are at any given time, making it easy to find them in the event that they escape, are stolen, or get lost.