Skip to content

Commit d3f3df0

Browse files
Erik JunghannsCalcProgrammer1
authored andcommitted
Improve PawnIO initialization
1 parent 13edc40 commit d3f3df0

1 file changed

Lines changed: 34 additions & 25 deletions

File tree

i2c_smbus/Windows/i2c_smbus_pawnio.cpp

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -173,29 +173,7 @@ HRESULT i2c_smbus_pawnio::start_pawnio(std::string filename, PHANDLE phandle)
173173
HANDLE handle;
174174
HRESULT status;
175175

176-
/*-----------------------------------------------------*\
177-
| Open PawnIO driver |
178-
\*-----------------------------------------------------*/
179-
status = pawnio_open(phandle);
180-
181-
/*-----------------------------------------------------*\
182-
| Check result |
183-
\*-----------------------------------------------------*/
184-
if(status)
185-
{
186-
if(status == E_ACCESSDENIED)
187-
{
188-
LOG_ERROR("Permission Denied, PawnIO initialization aborted");
189-
}
190-
else
191-
{
192-
LOG_ERROR("Could not open PawnIO, PawnIO initialization aborted");
193-
}
194-
195-
return(status);
196-
}
197-
198-
handle = *phandle;
176+
LOG_INFO("Start PawnIO: %s", filename.c_str());
199177

200178
/*-----------------------------------------------------*\
201179
| Get the path of the executable |
@@ -243,6 +221,27 @@ HRESULT i2c_smbus_pawnio::start_pawnio(std::string filename, PHANDLE phandle)
243221
\*-----------------------------------------------------*/
244222
file.close();
245223

224+
/*-----------------------------------------------------*\
225+
| Open PawnIO driver |
226+
\*-----------------------------------------------------*/
227+
status = pawnio_open(phandle);
228+
229+
if(status)
230+
{
231+
if(status == E_ACCESSDENIED)
232+
{
233+
LOG_ERROR("Permission Denied, PawnIO initialization aborted");
234+
}
235+
else
236+
{
237+
LOG_ERROR("Could not open PawnIO, PawnIO initialization aborted");
238+
}
239+
240+
return(status);
241+
}
242+
243+
handle = *phandle;
244+
246245
/*-----------------------------------------------------*\
247246
| Load the file into PawnIO |
248247
\*-----------------------------------------------------*/
@@ -253,15 +252,25 @@ HRESULT i2c_smbus_pawnio::start_pawnio(std::string filename, PHANDLE phandle)
253252
\*-----------------------------------------------------*/
254253
if(status)
255254
{
256-
LOG_ERROR("Failed to load %s, PawnIO initialization aborted", filename.c_str());
255+
pawnio_close(handle);
256+
257+
if (status == HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED))
258+
{
259+
LOG_INFO("PawnIO module initialization aborted (unsupported)");
260+
}
261+
else
262+
{
263+
LOG_ERROR("PawnIO module initialization aborted (code=%ld)", status);
264+
}
265+
257266
return(status);
258267
}
259268

260269
/*-----------------------------------------------------*\
261270
| Log a message and return OK if PawnIO successfully |
262271
| opened |
263272
\*-----------------------------------------------------*/
264-
LOG_INFO("PawnIO initialized");
273+
LOG_INFO("PawnIO initialized successully");
265274
return(S_OK);
266275
}
267276

0 commit comments

Comments
 (0)