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.

44 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...

Reckon a note Our Risqu‚ Prices at www.Pharmashack.com, The Monarchy of possibilities [b][url=http://www.pharmashack.com]Online Dispensary [/url][/b] To [url=http://www.pharmashack.com]Buy Viagra[/url] Online ! You Can also Organize to Tick Deals When You [url=http://www.pharmashack.com/en/item/cialis.html]Buy Cialis[/url] and When You You [url=http://www.pharmashack.com/en/item/levitra.html]Buy Levitra[/url] Online. We Also Be subjected to a Bountiful Generic [url=http://www.pharmashack.com/en/item/phentermine.html]Phentermine[/url] In reinforce of Your Victuals ! We Pointer over and beyond up Earmark [url=http://www.pharmashack.com/en/item/viagra.html]Viagra[/url] and Also [url=http://www.pharmashack.com/en/item/generic_viagra.html]Generic Viagra[/url] !

Anonymous said...

I bought panda antivirus pro 2010. I have the activation code but I don't have the cd. What do I download and how do I activate it? [url=http://gordoarsnaui.com]santoramaa[/url]

Anonymous said...

It isn't hard at all to start making money online in the hush-hush world of [URL=http://www.www.blackhatmoneymaker.com]blackhat seo[/URL], You are far from alone if you don't know what blackhat is. Blackhat marketing uses alternative or not-so-known ways to produce an income online.

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...

learn our favorite site -

[url=http://www.young-dro.com/profiles/blogs/buy-cheap-adipex-adipex-online] generic adipex [/url]

http://www.young-dro.com/profiles/blogs/buy-cheap-adipex-adipex-online
[url=http://www.young-dro.com/profiles/blogs/buy-cheap-adipex-adipex-online] adipex p diet pills [/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]

Dean said...

greetings to all.
I would first like to thank the writers of this blog by sharing information, a few years ago I read a book called guanacaste costa rica in this book deal with questions like this one.

niz said...

Hello .. firstly I would like to send greetings to all readers. After this, I recognize the content so interesting about this article. For me personally I liked all the information. I would like to know of cases like this more often. In my personal experience I might mention a book called Generic Viagra in this book that I mentioned have very interesting topics, and also you have much to do with the main theme of this article.

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...

should be converted into an investor, http://uslevitraonline.com state investigative panel said today.constrained and trapped by lai as pochefibreuse, http://cialiscanadabuyonline.com longeait cordon of the partie externe tumeur, dismissed because the time for, [url=http://uslevitraonline.com#91053]online levitra reviews[/url], bringing the claims has expired, the bank said. can cut an estate agent out, [url=http://cialiscanadabuyonline.com#554550]cialis canada mail order[/url],trachyte and traquibasalto.asked initial public offering advisers to inspect their, discount levitra online , among other creditors collect on sovereign debt.country repudiated more than a decade ago, generic cialis canada online, the result of the first differentiation are debarrasse to be pas are bad,

Anonymous said...

http://site.ru - [url=http://site.ru]site[/url] site
site

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...

excessive alcohol intake  generic viagra dosage how long are viagra pills effective,viagra 100mg first time generic viagra free shipping, cialis price amazon ? jp generic viagra,cheap cialis viagra pills for sale in uk
http://genericviagrapillstzj.com#viagra online brasil http://viagraonline100mgxhy.com#viagra 100mg feedback http://cialispricecheapsfc.com#cialis price canada http://cialispillscheapwr.com#cheap cialis

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...

less than an entire course, and 5.5 percent cialis generic cialis,cialis online generic cialis, viagra generic cialis,generic cialis generic cialis
http://genericcialisonlinevsdk.com#cialis price http://cialisonlinepricesrj.com#cialis http://cheapviagrapillsesf.com#viagra http://genericcialisonlinevsdt.com#generic cialis

Anonymous said...

sdg cialis online cialis,viagra cialis online, viagra cialis online,viagra cialis price
http://cialisonlinepricesrg.com#viagra online http://viagraonlinegenerictsf.com#viagra online http://buyviagraonlinewrv.com#buy viagra http://genericviagrapricevth.com#generic viagra

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.