AdvancedHMI Software

General Category => Support Questions => Topic started by: ddddd13 on June 15, 2019, 08:48:19 AM

Title: Message Handler
Post by: ddddd13 on June 15, 2019, 08:48:19 AM
Archie;

I cannot remember how the Message Handler works. I know I need to enter the SMPT info, but what calls the message handler itself. Example, I have a button called send message. How does that run the message handler. Also there is a variable in the property called Value. Is that the # in the emailer that will be used? Example 5 would use the fifth line in the file which has the number of the person to email, the time to wait, the number of the second person to email, the time to wait, and the number of the third person to email.

Thanks,
Dave
Title: Re: Message Handler
Post by: Archie on June 15, 2019, 10:33:04 AM
The value indicates the message number and a change in value will initiate sending an email as defined in the AlarmToEmail.txt

The first digit in AlarmToEmail.txt indicates the message number
Title: Re: Message Handler
Post by: ddddd13 on June 15, 2019, 12:44:42 PM
Archie;

I assume the following is what you mean by changing the value. Keep in mind it starts with 0
MessageHandler1.Value = 1

It does not work. We tested MessageHandlerPLC I don't remember if we tested MessageHandler.

I have tried sending from three different email servers including yours.

Any more ideas?

Dave
Title: Re: Message Handler
Post by: Archie on June 15, 2019, 01:06:25 PM
- Set EnableEventLogging to True
- Run the Application
- Post the contents of ErrorLog.txt and EventLog.txt
Title: Re: *!*#@**!!! VS
Post by: ddddd13 on June 15, 2019, 01:26:30 PM
VS SUCKS!!!!
Why do they think they are better at deciding when and what to save. They Crashed another form. If I was able to save it when I wanted to and not have to worry about them overwritting I could simply go back to the last copy and start over without having to redesign the entire form. How %&*#@
stupid.

Dave
Title: Re: Message Handler
Post by: Archie on June 15, 2019, 01:39:10 PM
Any time you run the application Visual Studio will save all the files, so you will at least have up until the last time you ran the application.
Title: Re: *&*%#@ VS
Post by: ddddd13 on June 15, 2019, 01:40:11 PM
Now I have a blank form. On this page is supposed to be 48 radio buttons. if I try to load a radio button from the tool box it labels it radio button 49. How can I delete the form to get rid everything associated with the form and start over?

Dave
Title: Re: Message Handler
Post by: Archie on June 15, 2019, 01:47:00 PM
- Windows -> Close All Documents
- Close Visual Studio
- Re-open the project in VS
- Build->Rebuild Solution
- In Solution Explorer double click the form you want to open
Title: Re: VS SUCKS
Post by: ddddd13 on June 15, 2019, 02:10:21 PM
I did one better I rebooted restarted VS and loaded operator reports. Blank Screen. The code is there yet but the controls are not on the screen.

Dave
Title: Re: Message Handler
Post by: Archie on June 15, 2019, 02:27:47 PM
With VS 2019, it is important to close all document because it has a startup bug when a design view is open.

In VS2019, "Reopen documents on solution load" is actually a good option to uncheck (Found in Tools->Options->Projects and Solutions):
Title: Re: Message Handler
Post by: ddddd13 on June 15, 2019, 02:56:57 PM
How do I now get rid of that form to start over.

Dave
Title: Re: Message Handler
Post by: Archie on June 15, 2019, 03:04:06 PM
If you are sure you want to completely delete it with no recovery possible, then right click it in Solution Explorer and select Delete
Title: Re: Message Handler
Post by: ddddd13 on June 15, 2019, 03:26:54 PM
I did as you suggested now I have a copy of the correct form in the second solution. But again I cannot right click and click use existing as the form operator reports.vb[Design] or any form with [Design] are not found. In other words how do I get that back to the first solution that has the corrupted designer form?

Dave
Title: Re: Message Handler
Post by: Archie on June 15, 2019, 03:30:07 PM
In the second solution in Solution Explorer, right click AdvancedHMI project and select Open Folder in File Explorer.
Do you then see these 2 files?

OperatorReports.designer.vb
OperatorReports.vb
Title: Re: Message Handler
Post by: ddddd13 on June 15, 2019, 03:35:38 PM
yes
Title: Re: Message Handler
Post by: ddddd13 on June 15, 2019, 03:44:11 PM
I copied them over and now I get a bunch of errors form change button undeclared ect ect ect These are left over from the last form I am sure.

Dave
Title: Re: Message Handler
Post by: Archie on June 15, 2019, 03:47:03 PM
- Open your first solution in Visual Studio
- In Solution Explorer right click AdvancedHMI and select Add->Existing Item
- Browse to the folder where you saw the 2 files
- Select the OperatorReports.vb and click the Add button
- It may ask to replace files 2 or 3 times, click Yes each time
Title: Re: Message Handler
Post by: Archie on June 15, 2019, 03:49:58 PM
Check to see if both solutions use the same version of AdvancedHMI

- Open your first solution
- In Solution Explorer, right click the AdvancedHMI project and select Properties
- In the Application Tab click the Assembly Information button
- Make note of the Assembly Version
- Repeat this for the second solution

Do they match?
Title: Re: Message Handler
Post by: ddddd13 on June 17, 2019, 08:20:39 AM
I finally got it all straightened out. It is hard to tell but I think if I stop the program with a value other than 0 MessageHandler1.Value It corrupts the program. If I make sure the value is 0 before ending it does not crash. Does that make sense? Moving on!

The attached is the error log using excite and gmail emails. I have tried using yours but it seems to have been turned off. Excite rejects the connection all together. gmail reports unrecognized command even with the wrong address.

Can you recommend a email provider?

Thanks,
Dave
Title: Re: Message Handler
Post by: Archie on June 17, 2019, 11:16:20 AM
Getting the public email servers to relay email from an application can sometimes be tricky. They usually have precautions in place to keep spam bots from flooding their servers. For me Gmail has been the most difficult because of their tight security.

For excite it looks like the SMTPserver is smtp.excite.com
SMTPLoginUserName is your email address
SMTPLoginPassword  is your email password
SMTP port 465

One place did say UseSSL must be true.

Title: Re: Message Handler
Post by: ddddd13 on June 17, 2019, 01:23:48 PM
Archie;

I could not get gmail to work. I tried mail.com and it would send about 50% of the e-mails however, now it won't send any it just comes back with mailbox unavailable.

But now I have the form eater problem coming back in. I get the alarm. The designer can not process the code at line 77: Me.MessageHandler1=new AdvancedHMIControls.MessageHandler() The code within the method 'Initialize Component' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again.

I have not changed this code and the only thing I write to is MessageHandler1.Value= (0 when I exit 1 when I click a button) Setting it to 0 on exit has prevented this problem all morning but now it is back. I can do a clean I can exit and start again but it will give me the same error. I have learned and saved a copy without the error to a different directory and can just copy that version over the top of the one with the error. But this has always been a problem for me. If I press the ignore and continue it will eat the form!
Thanks
Dave
Title: Re: Message Handler
Post by: Archie on June 17, 2019, 01:54:43 PM
Did you try

- Windows->Close All Documents
- Exit Visual Studio
- Re-open Visual Studio
- Build->Rebuild Solution
Title: Re: Message Handler
Post by: Archie on June 17, 2019, 02:26:35 PM
If you had mail.com work initially then stop, my guess is that you reached the daily limit of outgoing relays.
Title: Re: Message Handler
Post by: ddddd13 on June 17, 2019, 03:42:22 PM
Archie;

Remember I have rebooted the computer! Once that file gets corrupted you dead, dead, dead! You need to erase it and copy a previously saved version into its place.

Daily limit of emails? What do you mean to send thru advanced hmi or the email server. I am now trying fastmail.com and am getting different errors. Look at the attachment. Pay attention to the time. It shows an email attempt every 2 minutes yet in the emailer file it should be emailing every minute???

Dave
Title: Re: Message Handler
Post by: ddddd13 on June 17, 2019, 03:43:26 PM
The error log
Title: Re: Message Handler
Post by: Archie on June 17, 2019, 03:55:33 PM
Remember I have rebooted the computer! Once that file gets corrupted you dead, dead, dead! You need to erase it and copy a previously saved version into its place.

Daily limit of emails? What do you mean to send thru advanced hmi or the email server. I am now trying fastmail.com and am getting different errors. Look at the attachment. Pay attention to the time. It shows an email attempt every 2 minutes yet in the emailer file it should be emailing every minute???
Even if you reboot the PC, it will not fix it. The most important step is to do the Windows->Close All Documents. Otherwise VS just re-opens into the same error. This is a known issue with VS2019 and I see it on a daily basis, but I have never "lost" a form.

The daily limit is set by the hosting email server. I have not been able to find the limit set by mail.com , but this web site will give you a general idea of limits that providers set:

https://docs.mailpoet.com/article/49-lists-of-hosts-and-their-sending-limits
Title: Re: Message Handler
Post by: Archie on June 17, 2019, 03:58:52 PM
Can you attach your AlarmToEmail.txt file?
Title: Re: Message Handler
Post by: ddddd13 on June 17, 2019, 04:45:55 PM
Archie;

I changed from fastmail back to mail. I got 5 emails to send the sixth did not go thru. The following is the error I am getting in the log.


6/17/2019 3:38:58 PM - Send Message : This operation cannot be performed while a message is being sent.
6/17/2019 3:38:58 PM - An asynchronous call is already in progress. It must be completed or canceled before you can call this method.
6/17/2019 3:38:58 PM - System.Net.Mail.SmtpException: Syntax error, command unrecognized. The server response was:
   at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.End(IAsyncResult result)
   at System.Net.Mail.SmtpTransport.EndGetConnection(IAsyncResult result)
   at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result)

Is this the Message Handler thinking it is not complete?

Attached is the emailer file.
Title: Re: Message Handler
Post by: Archie on June 17, 2019, 04:58:09 PM
It's trying to send the next email before the last was completed. The easiest fix is to use a synchronous send.

- In Solution Explorer, right click MessageHandler.vb and select View Code
- Go to line 288 and look for "Client.SendAsync(mm, Nothing)"
- Change that line to
Code: [Select]
Client.Send(mm)
Title: Re: Message Handler
Post by: ddddd13 on June 17, 2019, 05:19:16 PM
Archie;

it was on line 286 and I changed it but I get the alarm mailbox unavailable. I looked at mail.com and they claim they do not limit the number or  size of emails but they do limit what they might consider spam. These emails all look the same and they may consider them spam. I will wait a couple of hours and try again. If it works my problem is solved.
At this point do you suggest putting 286 back to the way it was.

Dave
Title: Re: Message Handler
Post by: Archie on June 17, 2019, 06:13:13 PM
Post the MessageHandler.vb file you currently have and I will have to modify it to handle faster value changes.
Title: Re: Message Handler
Post by: ddddd13 on June 17, 2019, 09:00:52 PM
Archie;

I don't think that is the problem. Making the changes you suggested to line *86 didn't work. I set MessageHandler1.value to 1 with the click of a button. When I leave the form (by clicking a form change button)I have the value being set back to 0. It will not change forms with line*86 that way.

The MessageHandler is being overrun because the server either the xmiter or the receiver locks it out for four hours. I have tested this and after 4 hours I can send 5 emails no more. I have changed the size of the emails by changing the text in the message and heading. I also waited 5 minutes between sending the emails. It still locks it out at 5 emails every 4 hours. This should not be a problem as they will have their own email server and should be able to set it up to allow more emails than 5. I have tried changing the username to see if it would accept another email but it will not until the 4 the hour as it is still the same server.

With all that said I have a couple of other questions.

Can I run more than one message handler at a time?
Can I run the Messagehandler and MessageHandlerPLC at the same time?
I noticed a variable in the messageHandler called acknowledge, what is this?
Is there feedback telling when the messagehandler is complete?
Is there a way to interrupt the MessageHandler i.e. set MessageHandler.Value to 0 and it stops?

Thanks again,
Dave

PS Did you get a price and invoice on the fanless PCs?
Title: Re: Message Handler
Post by: Archie on June 17, 2019, 09:19:44 PM
I need to re-think and rework the message handler because as-is it can only handle processing one message at a time. If one was initiated, then another alarm occurs before all 3 emails were sent from the first, it will not complete the 3 from the first. I need to set it up to queue alarms and handle unlimited simultaneous active alarms.

The Acknowledge property is used to stop any further emails from being sent for the current alarm.

You can use MessageHandler and MessageHandlerPLC at the same time.
Title: Re: Message Handler
Post by: ddddd13 on June 17, 2019, 09:45:29 PM
Archie;

Attached is the message handler

Dave
Title: Re: Message Handler
Post by: ddddd13 on June 17, 2019, 10:17:14 PM
Archie;

Very peculiar!

I am using mail.com to send a message to excite.com it is now locked out for another 3 hours with advanced hmi. However, I can send a email from my laptop using mail.com sending it to excite.com and it works?

That's a head scratcher!!!

Dave
Title: Re: Message Handler
Post by: ddddd13 on June 18, 2019, 12:59:04 AM
Archie:

I added a second Message Handler and a second button to launch it. I ran the first message handler waited 10 seconds and then ran the 2nd. They both sent their messages however they alarmed out after 5 messages.

The point. I think designing a message handler to accept an unlimited number of emails is a big job and overkill for what we need to do. From what I can see in the code the only real problem would be in recording the events and alarms.

I could copy the message handler and rename it to messagehandlerA,B, and C. 3 of them. Change the code to open event log A,B,C and alarm log A,B,C. Then the only thing I would need is feedback to tell me when the message handler is complete. From there it would be easy to select an available handler for the next email.

What do you think?

Dave
Title: Re: Message Handler
Post by: Archie on June 18, 2019, 06:46:42 AM
I completely revamped the MessageHandler to use independent timers for each message, run multithreaded, and use a queue for email sending. This gets around the problems related to the message handler. I will post the code later this morning after I do a little more testing.
Title: Re: Message Handler
Post by: ddddd13 on June 18, 2019, 07:01:14 AM
Archie;

I just tested using two message handlers again this morning it worked fine to 5 emails.

But if you already did a new one, wow! It will be interesting to see how you handled the multi thread problem.

Thanks,
Dave
Title: Re: Message Handler
Post by: Archie on June 18, 2019, 04:28:34 PM
This version has major changes, so I'm sure there will need to be some debugging. But overall it is much more robust.

- Download the attached file
- Unzip the file
- Open you project in Visual Studio
- Right click the AdvancedHMI project and select Add->Existing item (if these files were put in a folder, you will need to right click the folder.
- Browse to and select all of the files the were extracted
- Make sure it asks you to replace existing files (if not they are not replacing the old ones)
- Rebuild Solution
Title: Re: Message Handler
Post by: ddddd13 on June 18, 2019, 09:03:59 PM
Archie;

This is scary! I did what you instructed, and got the following error on rebuild.

'Count' is not a member of 'String()'.

8 times.

I do not see count in the property box but will dig deeper.

Dave
Title: Re: Message Handler
Post by: ddddd13 on June 18, 2019, 09:05:31 PM
Archie;

I also got this one.

Severity   Code   Description   Project   File   Line   Suppression State
Error      Could not copy the file "obj\Debug\AdvancedHMICS.exe" because it was not found.   AdvancedHMIcs         
Dave
Title: Re: Message Handler
Post by: ddddd13 on June 18, 2019, 09:10:34 PM
Archie;

I did something wrong the message handler code is the same as the old one, or the old one no longer exists? I don't know.

Dave
Title: Re: Message Handler
Post by: Archie on June 18, 2019, 09:18:04 PM
Archie;

This is scary! I did what you instructed, and got the following error on rebuild.

'Count' is not a member of 'String()'.

8 times.

I do not see count in the property box but will dig deeper.
If you double click on the error, what line of code does it take you to?
Title: Re: Message Handler
Post by: Godra on June 18, 2019, 10:42:08 PM
Try changing Count to Length or use the attached files.
Title: Re: Message Handler
Post by: Archie on June 18, 2019, 11:35:48 PM
Godra is correct. Any error that goes to ".count" should be changed to ".length"

Arrays should use the Length property, but I tend to use Count out of habit. For a reason that I cannot explain, it compiles with no errors on my PC, but often not on others.
Title: Re: Message Handler
Post by: ddddd13 on June 19, 2019, 08:40:01 AM
Archie;

I am in the field today. I will look at it tomorrow.

Thanks,
Dave
Title: Re: Message Handler
Post by: ddddd13 on June 21, 2019, 07:57:07 AM
Dear Sirs;

Funny I was able to do this before? I am stuck on your instructions of how to install the new message handler.

Right Click on AdvancedHMI project click add existing.

I can't seem to find it.

Thanks,
Dave
Title: Re: Message Handler
Post by: Archie on June 21, 2019, 08:34:50 AM
You can also click once on the AdvancedHMI project in Solution Explorer and Ctrl-Alt-A

If the current MessageHandlers are in a sub-folder, be sure to click on the folder. Otherwise you will get 2 copies and generated a slew of errors.
Title: Re: Message Handler
Post by: ddddd13 on June 21, 2019, 09:16:07 AM
Archie;

On the email form I have messagehandler1 and 2 these 2 where developed with the old messagehandler. After adding existing from the messagehandler download. (It did ask me to replace files). I added messagehandler4 I will send a pic of the properties window to your phone.

Attached is the error and event files. The 8:04 email was sent and received! This was using the old message handler. The others where not received, maybe not sent using the new message handler.

Thanks,
Dave
Title: Re: Message Handler
Post by: ddddd13 on June 21, 2019, 09:49:01 AM
Archie;

Ok I erased messagehandler 1 and 2 from the form. I did the add to existing and loaded the six files unzipped in the folder. Added messagehandler1 to the form and tried it. It worked! No error log 1 message sent in the event log and 1 message received.

I am now at my 5 email limit, so I will have to wait 4 hours before I can test it more.

You talked about a multi thread emailer. Right now I am setting 1 to value, I assume setting it to two will now send the email to what is in the emailer file 2nd on the list. If it was at 1 and I change it to two will it finish out the emails from one? And does acknowledge still interrupt it? If so how does it know to interrupt 1 or 2?

Thanks,
Dave
Title: Re: Message Handler
Post by: Archie on June 21, 2019, 10:00:33 AM
You talked about a multi thread emailer. Right now I am setting 1 to value, I assume setting it to two will now send the email to what is in the emailer file 2nd on the list. If it was at 1 and I change it to two will it finish out the emails from one? And does acknowledge still interrupt it? If so how does it know to interrupt 1 or 2?
Yes, it will send to the recipient for message 2 while continuing to send for message 1. Setting Acknowledge will stop all messages from sending further emails.
Title: Re: Message Handler
Post by: ddddd13 on June 21, 2019, 02:41:49 PM
Archie;

I setup a button that increments the value of Messaghandler1.Value by 1.

When I run the program, I press the button wait 15 seconds, press it again, wait another 15 seconds press it again.

I should get emails from alarm1, then alarm 2, then alarm 3, then alarm 1, then alarm2, then alarm3, then alarm1, then alarm2, then alarm3.

It seems the last alarm turns off the others as I get an email from alarm1, then alarm2, then alarm3, then alarm3, then alarm3.

Thanks,
Dave
Title: Re: Message Handler
Post by: Archie on June 21, 2019, 03:09:25 PM
Can you post your AlarmToEmail.txt file so I can test with the same thing.
Title: Re: Message Handler
Post by: ddddd13 on June 21, 2019, 03:12:54 PM
Archie;

Here it is.

Dave
Title: Re: Message Handler
Post by: Archie on June 21, 2019, 03:47:15 PM
I did find one minor bug:

- In Solution Explorer right click MessageHandler.vb and select View Code
- Go to Line 306 and change m_Value to mm.Subject
Code: [Select]
sw.WriteLine(Now() & " : (1.1)Email attempt for alarm " & mm.Subject & ", to : " & mm.To.ToString)
Title: Re: Message Handler
Post by: Archie on June 21, 2019, 03:58:33 PM
After I made the correction to make the EventLog.txt report correctly, I ran a similar test. I set Value to 1, wait 10 seconds, set Value to 2, wait 10 seconds and set Value to 3

This is my event log:

6/21/2019 3:53:18 PM : (1.1)Email attempt for alarm Machine : Alarm =1 - 6/21/2019 3:53:15 PM, to :
6/21/2019 3:53:31 PM : (1.1)Email attempt for alarm Machine : Alarm =2 - 6/21/2019 3:53:24 PM, to :
6/21/2019 3:53:37 PM : (1.1)Email attempt for alarm Machine : Alarm =3 - 6/21/2019 3:53:34 PM, to :
6/21/2019 3:54:18 PM : (1.1)Email attempt for alarm Machine : Alarm =1 - 6/21/2019 3:54:15 PM, to :
6/21/2019 3:54:27 PM : (1.1)Email attempt for alarm Machine : Alarm =2 - 6/21/2019 3:54:24 PM, to :
6/21/2019 3:54:37 PM : (1.1)Email attempt for alarm Machine : Alarm =3 - 6/21/2019 3:54:34 PM, to :
6/21/2019 3:55:18 PM : (1.1)Email attempt for alarm Machine : Alarm =1 - 6/21/2019 3:55:15 PM, to :
6/21/2019 3:55:31 PM : (1.1)Email attempt for alarm Machine : Alarm =2 - 6/21/2019 3:55:24 PM, to :
6/21/2019 3:55:37 PM : (1.1)Email attempt for alarm Machine : Alarm =3 - 6/21/2019 3:55:34 PM, to :
Title: Re: Message Handler
Post by: Taka_Y on October 09, 2019, 01:09:06 AM
Hello,
I would like to make error log file data by "MessageListByItem".
Can it be used for this MessageHandler.vb?

Best regards,
Taka